content
stringlengths 0
894k
| type
stringclasses 2
values |
---|---|
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the 'License'). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# $Revision: #17 $
import json
import os
import resource_manager_common.constant as c
from resource_manager.test import base_stack_test
from resource_manager.test import lmbr_aws_test_support
import test_constant
class IntegrationTest_CloudGemFramework_ExternalResource(base_stack_test.BaseStackTestCase):
# Fails in cleanup to keep the deployment stack intact for the next test rerun.
FAST_TEST_RERUN = False
def __init__(self, *args, **kwargs):
self.base = super(IntegrationTest_CloudGemFramework_ExternalResource, self)
self.base.__init__(*args, **kwargs)
def setUp(self):
self.set_deployment_name(lmbr_aws_test_support.unique_name())
self.set_resource_group_name(lmbr_aws_test_support.unique_name('rg'))
self.prepare_test_environment("cloud_gem_external_resource_test")
self.register_for_shared_resources()
def test_security_end_to_end(self):
self.run_all_tests()
def __000_create_stacks(self):
self.lmbr_aws('cloud-gem', 'create', '--gem', self.TEST_RESOURCE_GROUP_NAME, '--initial-content', 'no-resources', '--enable', ignore_failure=True)
self.enable_shared_gem(self.TEST_RESOURCE_GROUP_NAME, 'v1', path=os.path.join(self.context[test_constant.ATTR_ROOT_DIR], os.path.join(test_constant.DIR_GEMS, self.TEST_RESOURCE_GROUP_NAME)))
self.base_create_project_stack()
def __010_add_external_resources_to_project(self):
project_template_path = self.get_gem_aws_path(
self.TEST_RESOURCE_GROUP_NAME, c.PROJECT_TEMPLATE_FILENAME)
if not os.path.exists(project_template_path):
with open(project_template_path, 'w') as f:
f.write('{}')
with self.edit_gem_aws_json(self.TEST_RESOURCE_GROUP_NAME, c.PROJECT_TEMPLATE_FILENAME) as gem_project_template:
project_extension_resources = gem_project_template['Resources'] = {}
project_extension_resources[_EXTERNAL_RESOURCE_1_NAME] = _EXTERNAL_RESOURCE_1_INSTANCE
project_extension_resources[_EXTERNAL_RESOURCE_2_NAME] = _EXTERNAL_RESOURCE_2_INSTANCE
project_extension_resources['GameDBTableRefernece'] = _EXTERNAL_RESOURCE_1_REFERENCE
def __020_update_project(self):
self.base_update_project_stack()
def __030_verify_external_resource_metadata_on_s3(self):
configuration_bucket = self.get_stack_resource_physical_id(self.get_project_stack_arn(), 'Configuration')
external_source_1_key = self.get_reference_metadata_key(_EXTERNAL_RESOURCE_1_NAME)
self.verify_reference_metadata_on_s3(configuration_bucket, external_source_1_key, _EXTERNAL_RESOURCE_1_REFERENCE_METADATA)
external_source_2_key = self.get_reference_metadata_key(_EXTERNAL_RESOURCE_2_NAME)
self.verify_reference_metadata_on_s3(configuration_bucket, external_source_2_key, _EXTERNAL_RESOURCE_2_REFERENCE_METADATA)
def __40_verify_project_service_lambda_permission(self):
project_stack_arn = self.get_project_stack_arn()
project_service_lambda_role = self.get_lambda_function_execution_role(project_stack_arn, 'ServiceLambda')
self.verify_role_permissions('project',
self.get_project_stack_arn(),
project_service_lambda_role,
[
{
'Resources': map(lambda suffix: _EXTERNAL_RESOURCE_1_ARN + suffix, _EXTERNAL_RESOURCE_1_RESOURCE_SUFFIX),
'Allow': _EXTERNAL_RESOURCE_1_ACTIONS
}
])
def __999_cleanup(self):
if self.FAST_TEST_RERUN:
print 'Tests passed enough to reach cleanup, failing in cleanup to prevent stack deletion since FAST_TEST_RERUN is true.'
self.assertFalse(self.FAST_TEST_RERUN)
self.unregister_for_shared_resources()
self.base_delete_deployment_stack()
self.base_delete_project_stack()
def get_lambda_function_execution_role(self, stack_arn, function_name):
function_arn = self.get_stack_resource_arn(stack_arn, function_name)
res = self.aws_lambda.get_function(FunctionName = function_arn)
role_arn = res['Configuration']['Role']
return role_arn[role_arn.rfind('/')+1:]
def get_reference_metadata_key(self, resource_name):
return 'reference-metadata/{}/{}.json'.format(self.TEST_PROJECT_STACK_NAME, resource_name)
def verify_reference_metadata_on_s3(self, configuration_bucket, key, expected_content):
self.verify_s3_object_exists(configuration_bucket, key)
content = self.aws_s3.get_object(Bucket=configuration_bucket, Key=key)['Body'].read()
self.assertEqual(json.loads(content), expected_content)
_EXTERNAL_RESOURCE_1_NAME = 'ExternalResource1'
_EXTERNAL_RESOURCE_2_NAME = 'ExternalResource2'
_EXTERNAL_RESOURCE_1_ARN = "arn:aws:dynamodb:us-west-2:9816236123:table/GameDBTable"
_EXTERNAL_RESOURCE_1_ACTIONS = [
"dynamodb:Scan",
"dynamodb:Query",
"dynamodb:PutItem",
"dynamodb:GetItem",
]
_EXTERNAL_RESOURCE_1_RESOURCE_SUFFIX = ["/*",""]
_EXTERNAL_RESOURCE_1_REFERENCE_METADATA = {
"Arn": _EXTERNAL_RESOURCE_1_ARN,
"PhysicalId": "GameDBTable",
"Permissions": {
"Action": _EXTERNAL_RESOURCE_1_ACTIONS,
"ResourceSuffix": _EXTERNAL_RESOURCE_1_RESOURCE_SUFFIX
}
}
_EXTERNAL_RESOURCE_1_INSTANCE = {
"Type": "Custom::ExternalResourceInstance",
"Properties": {
"ServiceToken": { "Fn::Join": [ "", [ "arn:aws:lambda:", { "Ref": "AWS::Region" }, ":", { "Ref": "AWS::AccountId" }, ":function:", { "Ref": "ProjectResourceHandler" } ] ] },
"ReferenceMetadata": _EXTERNAL_RESOURCE_1_REFERENCE_METADATA
},
"DependsOn": [
"CoreResourceTypes"
]
}
_EXTERNAL_RESOURCE_2_REFERENCE_METADATA = {
"Arn": "arn:aws:dynamodb:us-west-2:9816236123:table/PlayerDBTable",
"PhysicalId": "PlayerDBTable",
"Permissions": {
"Action": [
"dynamodb:Scan",
"dynamodb:PutItem",
"dynamodb:GetItem",
"dynamodb:DeleteItem",
"dynamodb:UpdateItem"
],
"ResourceSuffix": ["/*",""]
}
}
_EXTERNAL_RESOURCE_2_INSTANCE = {
"Type": "Custom::ExternalResourceInstance",
"Properties": {
"ServiceToken": { "Fn::Join": [ "", [ "arn:aws:lambda:", { "Ref": "AWS::Region" }, ":", { "Ref": "AWS::AccountId" }, ":function:", { "Ref": "ProjectResourceHandler" } ] ] },
"ReferenceMetadata": _EXTERNAL_RESOURCE_2_REFERENCE_METADATA
},
"DependsOn": [
"CoreResourceTypes"
]
}
_EXTERNAL_RESOURCE_1_REFERENCE = {
"Type":"Custom::ExternalResourceReference",
"Metadata": {
"CloudCanvas": {
"Permissions": [
{
"AbstractRole": "ServiceLambda"
}
]
}
},
"Properties": {
"ReferenceName": _EXTERNAL_RESOURCE_1_NAME,
"ServiceToken": { "Fn::Join": [ "", [ "arn:aws:lambda:", { "Ref": "AWS::Region" }, ":", { "Ref": "AWS::AccountId" }, ":function:", { "Ref": "ProjectResourceHandler" } ] ] }
},
"DependsOn": [
"CoreResourceTypes",
_EXTERNAL_RESOURCE_1_NAME,
_EXTERNAL_RESOURCE_2_NAME
]
}
| python |
from src.targets import *
from src.states import GameLevelState
from src.spawner import Spawner
def create_level_two(game):
spawners = list()
spawners.append(Spawner(spawn_type=Strawberry, ammunition=3, initial_delay=3.0, cooldown=2.0,
min_velocity=(160., -10.), max_velocity=(200., -40.), strategy_right=False,
screen=game.screen))
spawners.append(Spawner(spawn_type=Strawberry, ammunition=6, initial_delay=1.5, cooldown=3.0,
min_velocity=(160., -10.), max_velocity=(200., -40.), strategy_right=True,
screen=game.screen))
spawners.append(Spawner(spawn_type=Tangerine, ammunition=5, initial_delay=10., cooldown=1.0,
min_velocity=(160., -10.), max_velocity=(200., -40.), strategy_right=False))
spawners.append(Spawner(spawn_type=Kiwi, ammunition=10, initial_delay=20., cooldown=0.05,
min_velocity=(150., -10.), max_velocity=(240., -40.), strategy_right=True))
spawners.append(Spawner(spawn_type=Kiwi, ammunition=10, initial_delay=20., cooldown=0.05,
min_velocity=(150., -10.), max_velocity=(240., -40.), strategy_right=False))
spawners.append(Spawner(spawn_type=Pineapple, ammunition=5, initial_delay=5., cooldown=.4,
min_velocity=(190., -10.), max_velocity=(240., -40.), strategy_right=False))
spawners.append(Spawner(spawn_type=Lemon, ammunition=4, initial_delay=14., cooldown=1.0,
min_velocity=(200., -10.), max_velocity=(240., -40.), strategy_right=True))
spawners.append(Spawner(spawn_type=Grapes, ammunition=10, initial_delay=12., cooldown=.4,
min_velocity=(190., -10.), max_velocity=(240., -40.), strategy_right=False))
spawners.append(Spawner(spawn_type=Apple, ammunition=1, initial_delay=0.0, cooldown=0.05,
min_velocity=(100., -10.), max_velocity=(100., -40.), strategy_right=False))
spawners.append(Spawner(spawn_type=Fries, ammunition=2, initial_delay=5., cooldown=1.0,
min_velocity=(50., -10.), max_velocity=(100., -40.), strategy_right=False))
spawners.append(Spawner(spawn_type=Steak, ammunition=3, initial_delay=5., cooldown=4.0,
min_velocity=(50., -10.), max_velocity=(100., -40.), strategy_right=True))
return GameLevelState(game, spawners=spawners, start_timer=0.0, debug=False)
| python |
import time
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp
from kivymd.uix.button import MDRectangleFlatButton, MDRoundFlatIconButton, MDTextButton
from kivymd.uix.label import MDLabel, MDIcon
from kivymd.uix.screen import MDScreen
from kivy.app import App
Builder.load_string('''
<CameraClick>:
orientation:'vertical'
Camera:
id: camera
resolution: (640, 480)
play: False
ToggleButton:
text: 'Iniciar'
on_press: camera.play = not camera.play
size_hint_y: None
height: '48dp'
Button:
text: 'Tomar foto'
size_hint_y: None
height: '48dp'
on_press: root.capture()
''')
class CameraClick(BoxLayout):
def capture(self):
camera = self.ids['camera']
trimester = time.strftime("%Y%m%d_%%H%M%S")
camera.export_to_png("IMG_{}.png".format(trimester))
print("Captured")
class MainApp(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark" # "Light"
screen = MDScreen()
screen.add_widget(
MDIcon(
halign='center',
icon="language-python",
pos_hint={'x': 0, 'y': 0.3}
)
)
screen.add_widget(
MDLabel(
text="Object recognition",
pos_hint={'x': 0, 'y': 0.2},
halign="center"
)
)
screen.add_widget(
MDRoundFlatIconButton(
icon="camera",
text="Abrir cámara",
pos_hint={"center_x": 0.5, "center_y": 0.5},
)
)
screen.add_widget(
MDLabel(
text="Developed by \n henrydiaz",
pos_hint={"center_x": 0.5, "center_y": 0.2},
halign="center"
)
)
return screen
class Principal(App):
def build(self):
return CameraClick()
MainApp().run()
| python |
import logging
l = logging.getLogger("archinfo.arch_mips64")
try:
import capstone as _capstone
except ImportError:
_capstone = None
try:
import keystone as _keystone
except ImportError:
_keystone = None
try:
import unicorn as _unicorn
except ImportError:
_unicorn = None
from .arch import Arch, register_arch, Endness, Register
from .tls import TLSArchInfo
class ArchMIPS64(Arch):
def __init__(self, endness=Endness.BE):
super(ArchMIPS64, self).__init__(endness)
if endness == Endness.BE:
self.function_prologs = set((
# TODO
))
self.function_epilogs = set((
# TODO
))
self.triplet = 'mips64-linux-gnu'
self.linux_name = 'mips64'
self.ida_name = 'mips64b'
bits = 64
vex_arch = "VexArchMIPS64"
name = "MIPS64"
qemu_name = 'mips64el'
ida_processor = 'mips64'
linux_name = 'mips64el' # ???
triplet = 'mips64el-linux-gnu'
max_inst_bytes = 4
ret_offset = 32
syscall_register_offset = 16
call_pushes_ret = False
stack_change = -8
branch_delay_slot = True
sizeof = {'short': 16, 'int': 32, 'long': 64, 'long long': 64}
if _capstone:
cs_arch = _capstone.CS_ARCH_MIPS
cs_mode = _capstone.CS_MODE_64 + _capstone.CS_MODE_LITTLE_ENDIAN
if _keystone:
ks_arch = _keystone.KS_ARCH_MIPS
ks_mode = _keystone.KS_MODE_64 + _keystone.KS_MODE_LITTLE_ENDIAN
uc_arch = _unicorn.UC_ARCH_MIPS if _unicorn else None
uc_mode = (_unicorn.UC_MODE_64 + _unicorn.UC_MODE_LITTLE_ENDIAN) if _unicorn else None
uc_const = _unicorn.mips_const if _unicorn else None
uc_prefix = "UC_MIPS_" if _unicorn else None
function_prologs = set((
# TODO
))
function_epilogs = set((
# TODO
))
ret_instruction = b"\x08\x00\xE0\x03" + b"\x25\x08\x20\x00"
nop_instruction = b"\x00\x00\x00\x00"
instruction_alignment = 4
register_list = [
Register(name='zero', size=8, alias_names=('r0',)),
Register(name='at', size=8, alias_names=('r1',),
general_purpose=True),
Register(name='v0', size=8, alias_names=('r2',),
general_purpose=True, linux_entry_value='ld_destructor'),
Register(name='v1', size=8, alias_names=('r3',),
general_purpose=True),
Register(name='a0', size=8, alias_names=('r4',),
general_purpose=True, argument=True),
Register(name='a1', size=8, alias_names=('r5',),
general_purpose=True, argument=True),
Register(name='a2', size=8, alias_names=('r6',),
general_purpose=True, argument=True),
Register(name='a3', size=8, alias_names=('r7',),
general_purpose=True, argument=True),
Register(name='t0', size=8, alias_names=('r8', 'a4',),
general_purpose=True),
Register(name='t1', size=8, alias_names=('r9', 'a5',),
general_purpose=True),
Register(name='t2', size=8, alias_names=('r10', 'a6',),
general_purpose=True),
Register(name='t3', size=8, alias_names=('r11', 'a7',),
general_purpose=True),
Register(name='t4', size=8, alias_names=('r12',),
general_purpose=True),
Register(name='t5', size=8, alias_names=('r13',),
general_purpose=True),
Register(name='t6', size=8, alias_names=('r14',),
general_purpose=True),
Register(name='t7', size=8, alias_names=('r15',),
general_purpose=True),
Register(name='s0', size=8, alias_names=('r16',),
general_purpose=True),
Register(name='s1', size=8, alias_names=('r17',),
general_purpose=True),
Register(name='s2', size=8, alias_names=('r18',),
general_purpose=True),
Register(name='s3', size=8, alias_names=('r19',),
general_purpose=True),
Register(name='s4', size=8, alias_names=('r20',),
general_purpose=True),
Register(name='s5', size=8, alias_names=('r21',),
general_purpose=True),
Register(name='s6', size=8, alias_names=('r22',),
general_purpose=True),
Register(name='s7', size=8, alias_names=('r23',),
general_purpose=True),
Register(name='t8', size=8, alias_names=('r24',),
general_purpose=True),
Register(name='t9', size=8, alias_names=('r25',),
general_purpose=True, persistent=True),
Register(name='k0', size=8, alias_names=('r26',),
general_purpose=True),
Register(name='k1', size=8, alias_names=('r27',),
general_purpose=True),
Register(name='gp', size=8, alias_names=('r28',),
persistent=True),
Register(name='sp', size=8, alias_names=('r29',),
default_value=(Arch.initial_sp, True, 'global')),
Register(name='s8', size=8, alias_names=('r30', 'fp', 'bp'),
general_purpose=True),
Register(name='ra', size=8, alias_names=('r31', 'lr'),
general_purpose=True, persistent=True, linux_entry_value=0),
Register(name='pc', size=8, alias_names=('ip',)),
Register(name='hi', size=8, general_purpose=True),
Register(name='lo', size=8, general_purpose=True),
Register(name='f0', size=8, floating_point=True, subregisters=[('f0_lo', 0, 4)]),
Register(name='f1', size=8, floating_point=True, subregisters=[('f1_lo', 0, 4)]),
Register(name='f2', size=8, floating_point=True, subregisters=[('f2_lo', 0, 4)]),
Register(name='f3', size=8, floating_point=True, subregisters=[('f3_lo', 0, 4)]),
Register(name='f4', size=8, floating_point=True, subregisters=[('f4_lo', 0, 4)]),
Register(name='f5', size=8, floating_point=True, subregisters=[('f5_lo', 0, 4)]),
Register(name='f6', size=8, floating_point=True, subregisters=[('f6_lo', 0, 4)]),
Register(name='f7', size=8, floating_point=True, subregisters=[('f7_lo', 0, 4)]),
Register(name='f8', size=8, floating_point=True, subregisters=[('f8_lo', 0, 4)]),
Register(name='f9', size=8, floating_point=True, subregisters=[('f9_lo', 0, 4)]),
Register(name='f10', size=8, floating_point=True, subregisters=[('f10_lo', 0, 4)]),
Register(name='f11', size=8, floating_point=True, subregisters=[('f11_lo', 0, 4)]),
Register(name='f12', size=8, floating_point=True, subregisters=[('f12_lo', 0, 4)]),
Register(name='f13', size=8, floating_point=True, subregisters=[('f13_lo', 0, 4)]),
Register(name='f14', size=8, floating_point=True, subregisters=[('f14_lo', 0, 4)]),
Register(name='f15', size=8, floating_point=True, subregisters=[('f15_lo', 0, 4)]),
Register(name='f16', size=8, floating_point=True, subregisters=[('f16_lo', 0, 4)]),
Register(name='f17', size=8, floating_point=True, subregisters=[('f17_lo', 0, 4)]),
Register(name='f18', size=8, floating_point=True, subregisters=[('f18_lo', 0, 4)]),
Register(name='f19', size=8, floating_point=True, subregisters=[('f19_lo', 0, 4)]),
Register(name='f20', size=8, floating_point=True, subregisters=[('f20_lo', 0, 4)]),
Register(name='f21', size=8, floating_point=True, subregisters=[('f21_lo', 0, 4)]),
Register(name='f22', size=8, floating_point=True, subregisters=[('f22_lo', 0, 4)]),
Register(name='f23', size=8, floating_point=True, subregisters=[('f23_lo', 0, 4)]),
Register(name='f24', size=8, floating_point=True, subregisters=[('f24_lo', 0, 4)]),
Register(name='f25', size=8, floating_point=True, subregisters=[('f25_lo', 0, 4)]),
Register(name='f26', size=8, floating_point=True, subregisters=[('f26_lo', 0, 4)]),
Register(name='f27', size=8, floating_point=True, subregisters=[('f27_lo', 0, 4)]),
Register(name='f28', size=8, floating_point=True, subregisters=[('f28_lo', 0, 4)]),
Register(name='f29', size=8, floating_point=True, subregisters=[('f29_lo', 0, 4)]),
Register(name='f30', size=8, floating_point=True, subregisters=[('f30_lo', 0, 4)]),
Register(name='f31', size=8, floating_point=True, subregisters=[('f31_lo', 0, 4)]),
Register(name='fir', size=4, floating_point=True),
Register(name='fccr', size=4, floating_point=True),
Register(name='fexr', size=4, floating_point=True),
Register(name='fenr', size=4, floating_point=True),
Register(name='fcsr', size=4, floating_point=True),
Register(name='cp0_status', size=4),
Register(name='ulr', size=8),
Register(name='emnote', size=4, artificial=True),
Register(name='cond', size=4),
Register(name='cmstart', size=8),
Register(name='cmlen', size=8),
Register(name='nraddr', size=8),
Register(name='ip_at_syscall', size=8, artificial=True),
]
# http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf
dynamic_tag_translation = {
0x70000001: 'DT_MIPS_RLD_VERSION',
0x70000005: 'DT_MIPS_FLAGS',
0x70000006: 'DT_MIPS_BASE_ADDRESS',
0x7000000a: 'DT_MIPS_LOCAL_GOTNO',
0x70000011: 'DT_MIPS_SYMTABNO',
0x70000012: 'DT_MIPS_UNREFEXTNO',
0x70000013: 'DT_MIPS_GOTSYM',
0x70000016: 'DT_MIPS_RLD_MAP'
}
got_section_name = '.got'
ld_linux_name = 'ld.so.1'
elf_tls = TLSArchInfo(1, 16, [], [0], [], 0x7000, 0x8000)
register_arch([r'.*mipsel.*|.*mips64el|.*mipsel64'], 64, Endness.LE, ArchMIPS64)
register_arch([r'.*mips64.*|.*mips.*'], 64, 'any', ArchMIPS64)
| python |
# Copyright 2015, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * 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.
# * Neither the name of Google Inc. 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
# OWNER 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.
"""Tests transmission of tickets across gRPC-on-the-wire."""
import unittest
from grpc._adapter import _intermediary_low
from grpc._links import invocation
from grpc._links import service
from grpc.framework.interfaces.links import links
from grpc_test import test_common
from grpc_test._links import _proto_scenarios
from grpc_test.framework.common import test_constants
from grpc_test.framework.interfaces.links import test_cases
from grpc_test.framework.interfaces.links import test_utilities
_IDENTITY = lambda x: x
class TransmissionTest(test_cases.TransmissionTest, unittest.TestCase):
def create_transmitting_links(self):
service_link = service.service_link(
{self.group_and_method(): self.deserialize_request},
{self.group_and_method(): self.serialize_response})
port = service_link.add_port(0, None)
service_link.start()
channel = _intermediary_low.Channel('localhost:%d' % port, None)
invocation_link = invocation.invocation_link(
channel, 'localhost',
{self.group_and_method(): self.serialize_request},
{self.group_and_method(): self.deserialize_response})
invocation_link.start()
return invocation_link, service_link
def destroy_transmitting_links(self, invocation_side_link, service_side_link):
invocation_side_link.stop()
service_side_link.stop_gracefully()
def create_invocation_initial_metadata(self):
return (
('first invocation initial metadata key', 'just a string value'),
('second invocation initial metadata key', '0123456789'),
('third invocation initial metadata key-bin', '\x00\x57' * 100),
)
def create_invocation_terminal_metadata(self):
return None
def create_service_initial_metadata(self):
return (
('first service initial metadata key', 'just another string value'),
('second service initial metadata key', '9876543210'),
('third service initial metadata key-bin', '\x00\x59\x02' * 100),
)
def create_service_terminal_metadata(self):
return (
('first service terminal metadata key', 'yet another string value'),
('second service terminal metadata key', 'abcdefghij'),
('third service terminal metadata key-bin', '\x00\x37' * 100),
)
def create_invocation_completion(self):
return None, None
def create_service_completion(self):
return _intermediary_low.Code.OK, 'An exuberant test "details" message!'
def assertMetadataTransmitted(self, original_metadata, transmitted_metadata):
self.assertTrue(
test_common.metadata_transmitted(
original_metadata, transmitted_metadata),
'%s erroneously transmitted as %s' % (
original_metadata, transmitted_metadata))
class RoundTripTest(unittest.TestCase):
def testZeroMessageRoundTrip(self):
test_operation_id = object()
test_group = 'test package.Test Group'
test_method = 'test method'
identity_transformation = {(test_group, test_method): _IDENTITY}
test_code = _intermediary_low.Code.OK
test_message = 'a test message'
service_link = service.service_link(
identity_transformation, identity_transformation)
service_mate = test_utilities.RecordingLink()
service_link.join_link(service_mate)
port = service_link.add_port(0, None)
service_link.start()
channel = _intermediary_low.Channel('localhost:%d' % port, None)
invocation_link = invocation.invocation_link(
channel, 'localhost', identity_transformation, identity_transformation)
invocation_mate = test_utilities.RecordingLink()
invocation_link.join_link(invocation_mate)
invocation_link.start()
invocation_ticket = links.Ticket(
test_operation_id, 0, test_group, test_method,
links.Ticket.Subscription.FULL, test_constants.LONG_TIMEOUT, None, None,
None, None, None, None, links.Ticket.Termination.COMPLETION)
invocation_link.accept_ticket(invocation_ticket)
service_mate.block_until_tickets_satisfy(test_cases.terminated)
service_ticket = links.Ticket(
service_mate.tickets()[-1].operation_id, 0, None, None, None, None,
None, None, None, None, test_code, test_message,
links.Ticket.Termination.COMPLETION)
service_link.accept_ticket(service_ticket)
invocation_mate.block_until_tickets_satisfy(test_cases.terminated)
invocation_link.stop()
service_link.stop_gracefully()
self.assertIs(
service_mate.tickets()[-1].termination,
links.Ticket.Termination.COMPLETION)
self.assertIs(
invocation_mate.tickets()[-1].termination,
links.Ticket.Termination.COMPLETION)
def _perform_scenario_test(self, scenario):
test_operation_id = object()
test_group, test_method = scenario.group_and_method()
test_code = _intermediary_low.Code.OK
test_message = 'a scenario test message'
service_link = service.service_link(
{(test_group, test_method): scenario.deserialize_request},
{(test_group, test_method): scenario.serialize_response})
service_mate = test_utilities.RecordingLink()
service_link.join_link(service_mate)
port = service_link.add_port(0, None)
service_link.start()
channel = _intermediary_low.Channel('localhost:%d' % port, None)
invocation_link = invocation.invocation_link(
channel, 'localhost',
{(test_group, test_method): scenario.serialize_request},
{(test_group, test_method): scenario.deserialize_response})
invocation_mate = test_utilities.RecordingLink()
invocation_link.join_link(invocation_mate)
invocation_link.start()
invocation_ticket = links.Ticket(
test_operation_id, 0, test_group, test_method,
links.Ticket.Subscription.FULL, test_constants.LONG_TIMEOUT, None, None,
None, None, None, None, None)
invocation_link.accept_ticket(invocation_ticket)
requests = scenario.requests()
for request_index, request in enumerate(requests):
request_ticket = links.Ticket(
test_operation_id, 1 + request_index, None, None, None, None, 1, None,
request, None, None, None, None)
invocation_link.accept_ticket(request_ticket)
service_mate.block_until_tickets_satisfy(
test_cases.at_least_n_payloads_received_predicate(1 + request_index))
response_ticket = links.Ticket(
service_mate.tickets()[0].operation_id, request_index, None, None,
None, None, 1, None, scenario.response_for_request(request), None,
None, None, None)
service_link.accept_ticket(response_ticket)
invocation_mate.block_until_tickets_satisfy(
test_cases.at_least_n_payloads_received_predicate(1 + request_index))
request_count = len(requests)
invocation_completion_ticket = links.Ticket(
test_operation_id, request_count + 1, None, None, None, None, None,
None, None, None, None, None, links.Ticket.Termination.COMPLETION)
invocation_link.accept_ticket(invocation_completion_ticket)
service_mate.block_until_tickets_satisfy(test_cases.terminated)
service_completion_ticket = links.Ticket(
service_mate.tickets()[0].operation_id, request_count, None, None, None,
None, None, None, None, None, test_code, test_message,
links.Ticket.Termination.COMPLETION)
service_link.accept_ticket(service_completion_ticket)
invocation_mate.block_until_tickets_satisfy(test_cases.terminated)
invocation_link.stop()
service_link.stop_gracefully()
observed_requests = tuple(
ticket.payload for ticket in service_mate.tickets()
if ticket.payload is not None)
observed_responses = tuple(
ticket.payload for ticket in invocation_mate.tickets()
if ticket.payload is not None)
self.assertTrue(scenario.verify_requests(observed_requests))
self.assertTrue(scenario.verify_responses(observed_responses))
def testEmptyScenario(self):
self._perform_scenario_test(_proto_scenarios.EmptyScenario())
def testBidirectionallyUnaryScenario(self):
self._perform_scenario_test(_proto_scenarios.BidirectionallyUnaryScenario())
def testBidirectionallyStreamingScenario(self):
self._perform_scenario_test(
_proto_scenarios.BidirectionallyStreamingScenario())
if __name__ == '__main__':
unittest.main(verbosity=2)
| python |
class Solution:
def trap(self, height: [int]) -> int:
n = len(height)
l = [0]*(n+1)
r = [0]*(n+1)
for i in range(n):
l[i+1] = max(l[i], height[i])
for i in range(n-2, -1, -1):
r[i] = max(r[i+1], height[i+1])
print(l, r)
ans = 0
for i in range(n):
h = min(l[i], r[i])
if h > 0 and h > height[i]:
ans += h - height[i]
return ans
height = [0,1,0,2,1,0,1,3,2,1,2,1]
height = [4,2,0,3,2,5]
sol = Solution()
res = sol.trap(height)
print(res)
| python |
#source, from django-tracking
from django.conf import settings
import re
# threadlocals middleware for global usage
# if this is used elsewhere in your system, consider using that instead of this.
try:
from threading import local
except ImportError:
from django.utils._threading_local import local
_thread_locals = local()
def get_current_user():
return getattr(_thread_locals, 'user', None)
class ThreadLocals(object):
"""Middleware that gets various objects from the
request object and saves them in thread local storage."""
def process_request(self, request):
_thread_locals.user = getattr(request, 'user', None)
# this is not intended to be an all-knowing IP address regex
IP_RE = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
def get_ip(request):
"""
Retrieves the remote IP address from the request data. If the user is
behind a proxy, they may have a comma-separated list of IP addresses, so
we need to account for that. In such a case, only the first IP in the
list will be retrieved. Also, some hosts that use a proxy will put the
REMOTE_ADDR into HTTP_X_FORWARDED_FOR. This will handle pulling back the
IP from the proper place.
"""
# if neither header contain a value, just use local loopback
ip_address = request.META.get('HTTP_X_FORWARDED_FOR', request.META.get('REMOTE_ADDR', '127.0.0.1'))
if ip_address:
# make sure we have one and only one IP
try:
ip_address = IP_RE.match(ip_address)
if ip_address:
ip_address = ip_address.group(0)
else:
# no IP, probably from some dirty proxy or other device
# throw in some bogus IP
ip_address = '10.0.0.1'
except IndexError:
pass
return ip_address
#source:
# http://stackoverflow.com/questions/715234/python-dict-update-diff
def dict_diff(current, prev):
"""Return differences from dictionaries a to b.
Return a tuple of three dicts: (removed, added, changed).
'removed' has all keys and values removed from a. 'added' has
all keys and values that were added to b. 'changed' has all
keys and their values in b that are different from the corresponding
key in a.
modified due to added/removed reversal assumptions, now assuming current and previous are what they are.
Goal is to have added/removed be accurate and the changed be the PREVIOUS values in prev that are changed and reflected in current.
returns:
tuple of (added, removed, changed)
where
Added: fields:values not in prev now in current
Removed: field:values not in current that were in prev
Changed: field:values that changed from prev to current, and returning prev's values
"""
removed = dict()
added = dict()
changed = dict()
for key, value in current.items():
if key not in prev:
removed[key] = value
elif prev[key] != value:
changed[key] = prev[key]
for key, value in prev.items():
if key not in current:
added[key] = value
return added, removed, changed
DEFAULT_TEMPLATE = "auditcare/auditcare_config_broken.html"
def login_template():
return getattr(settings, 'LOGIN_TEMPLATE', DEFAULT_TEMPLATE)
def logout_template():
return getattr(settings, 'LOGGEDOUT_TEMPLATE', DEFAULT_TEMPLATE)
| python |
#Import Flask, dependencies, sessions, basics like from titanic example
import numpy as numpy
import os
import sqlalchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine, func
from flask import Flask, jsonify
#Setup database
engine = create_engine("sqlite:///Resources/hawaii.sqlite")
#Reflect database into new model
Base = automap_base()
Base.prepare(engine, reflect=True)
#Save reference variables to the tables
Measurement = Base.classes.measurement
Station = Base.classes.station
#Flask
app = Flask(__name__)
#Flask routes
@app.route("/")
def welcome():
#List all routes available
return(
f"Available Routes:<br><br>"
f"/api/v1.0/precipitation<br>"
f"/api/v1.0/stations<br>"
f"/api/v1.0/tobs<br>"
f"/api/v1.0/temp_calculator/START_DATE/END_DATE<br>"
f"For temp_calculator, enter the following formatting: /api/v1.0/temp_calculator/START_DATE/END_DATE in 'YYY-MM-DD'<br>"
f"If no END_DATE is specified, the end date is last entry in database: 2017-08-23.<br>"
)
@app.route("/api/v1.0/precipitation")
def precipitation():
#Communication session with Measurement database, query Measurement database for date and prcp data.
session = Session(engine)
prcp_results = session.query(Measurement.date, Measurement.prcp).all()
#Close session
session.close()
#Create dictionary of Measurement.date key and Measurement.prcp value
precipitation = []
for p in prcp_results:
p_dict = {}
p_dict["date"] = p.date
p_dict["prcp"] = p.prcp
precipitation.append(p_dict)
return jsonify(precipitation)
@app.route("/api/v1.0/stations")
def stations():
#Communication session with Stations database, query for stations.
session = Session(engine)
station_results = session.query(Station.station).all()
#Close session
session.close()
#Create unique list for stations in query by set, not using a dictionary which would also work.
station_list = []
for l in station_results:
station_list.append(l)
final_stations = list(set(station_list))
return jsonify(final_stations)
@app.route("/api/v1.0/tobs")
def temperature():
#Communication session with Measurement database, query for date and tobs after 2016-08-23
session = Session(engine)
temp_results = session.query(Measurement.date, Measurement.tobs).filter(Measurement.date>="2016-08-23")
#Close session
session.close()
#Like above, create dictionary of date and observed temperature for past year
temp_list = []
for t in temp_results:
t_dict = {}
t_dict["date"] = t.date
t_dict["tobs"] = t.tobs
temp_list.append(t_dict)
return jsonify(temp_list)
@app.route("/api/v1.0/temp_calculator/<start_date>/<end_date>")
def ave_temp(start_date,end_date="2017-08-23"):
#Communication session with Measurement database for temperature data over start and end dates
session = Session(engine)
#Query based on start and start/end dates. Uses func capabilities for calculations inside sqlalchemy session.query.
temp_calcs = session.query(func.min(Measurement.tobs), func.avg(Measurement.tobs), func.max(Measurement.tobs)).\
filter(Measurement.date >= start_date).filter(Measurement.date <= end_date)
calc_list = []
for c in temp_calcs:
calc_list.append(c)
#Returns final list for max, min, and average temps, start date.
return jsonify(calc_list, f"Start Date: {start_date}", f"End Date: {end_date}")
if __name__ == '__main__':
app.run(debug=True) | python |
from mutation_variants.helpers import *
def fair_rank( x ):
#ranks = []
ix = np.argsort(x)
sx = x[ix]
rnk = 0
old_x = sx[0]
ranks = [rnk]
cnter = 1
for xi in sx[1:]:
if xi > old_x:
rnk += 1 #cnter
cnter = 1
else:
cnter += 1
old_x = xi
ranks.append(rnk)
ranks = np.array(ranks, dtype=float)/float(rnk)
return ranks[np.argsort(ix)]
#
def fair_rank_order_normalization( X ):
#ORDER = np.argsort( -X, 1 )
Y = X.copy()
#vals = np.linspace(eps,1.0-eps,X.shape[1])
for idx in range(Y.shape[0]):
Y[idx,:] = fair_rank( Y[idx] )
return Y
def global_order_normalization( X ):
max_val = np.max(X)
return X.astype(float)/max_val
def load_from_csv( location, sep = "," ):
return pd.read_csv( location, sep = sep ) | python |
from .lfads import LFADS
from .tndm import TNDM
| python |
import collections
import sys
def anagram(string1, string2):
if not len(string1)==len(string2):
return False
def create_counter(from_string):
counter = collections.Counter()
for symbol in from_string:
counter[symbol] +=1
return counter
counter1 = create_counter(string1)
counter2 = create_counter(string2)
mentioned_symbols = set(counter1.keys()+counter2.keys())
for symbol in mentioned_symbols:
if not counter1[symbol]==counter2[symbol]:
return False
return True
words = [line.rstrip() for line in sys.stdin]
for word1 in words:
for word2 in words:
if not word1==word2:
if anagram(word1,word2):
print 'Anagram: ', word1, ' -- ', word2
| python |
#start menu of Game of Life
import pygame, sys, time, random
sys.path.append('../widgets')
from pygame.locals import *
from pygame import gfxdraw
from ListView import ListView
from Button import Button
from InputBox import InputBox
from Grid import Grid
FPS = 5
WINDOWWIDTH = 640
WINDOWHEIGHT = 480
CELLSIZE = 20
assert WINDOWWIDTH % CELLSIZE == 0, "Window width must be a multiple of cell size"
assert WINDOWHEIGHT % CELLSIZE == 0, "Window height must be a multiple of cell size"
CELLWIDTH = int(WINDOWWIDTH / CELLSIZE)
CELLHEIGHT = int(WINDOWHEIGHT / CELLSIZE)
WHITE = (255,255,255)
BLACK = ( 0, 0, 0)
GREEN = (0, 255, 0)
LIGHTGRAY = ( 211, 211, 211)
GRAY = (128, 128, 128)
DARKSLATEGRAY = (47, 79, 79)
SIMTYPE = 0
PAUSE = False
SCALE = None
def validInput(x):
return x.isdigit()
def main():
global FPSCLOCK, DISPLAYSURF, BASICFONT, TITLEFONT, SIMTYPE, WINDOWWIDTH, WINDOWHEIGHT
global PAUSE, SCALE
pygame.init()
infoObject = pygame.display.Info()
WINDOWWIDTH, WINDOWHEIGHT = infoObject.current_w, infoObject.current_h
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
BASICFONT = pygame.font.Font(None ,30)
TITLEFONT = pygame.font.Font('../assets/ka1.ttf',50)
pygame.display.set_caption('Game of Life')
initSimulator()
terminate()
def initSimulator():
pygame.draw.rect(DISPLAYSURF, DARKSLATEGRAY, (0, 0, WINDOWWIDTH//8, WINDOWHEIGHT), 0)
pygame.draw.line(DISPLAYSURF, GRAY, (WINDOWWIDTH//8, 0), (WINDOWWIDTH//8, WINDOWHEIGHT), 2)
L = ListView( 0, 0, WINDOWWIDTH//8, WINDOWHEIGHT, 10, 30)
startButton = Button(0, 0, 100, 50, 'Start', WHITE, BLACK, DARKSLATEGRAY, WHITE, 1)
input_box = InputBox(0, 0, 100, 50, 'scale:', 'set', validInput, 4)
taSetter = Button(0, 0, 100, 50, 'TA: OFF', WHITE, BLACK, DARKSLATEGRAY, WHITE, 1)
L.add_widget(startButton)
L.add_widget(input_box)
L.add_widget(taSetter)
grid = Grid(WINDOWWIDTH//8, 0, 7*WINDOWWIDTH//8, WINDOWHEIGHT, 20, WHITE, BLACK, GREEN)
input_box.set_value(20)
widgets = [startButton, input_box, taSetter]
while True:
for event in pygame.event.get():
if event.type == QUIT:
terminate()
for widget in widgets:
widget.handle_event(event)
grid.handle_event(event)
PAUSE = True if startButton.update()==0 or startButton.update()==2 else False
if PAUSE:
if startButton.update() != 0:
startButton.update_text('Resume')
else:
startButton.update_text('Pause')
SCALE = input_box.update()
taSetter.update()
grid.update(PAUSE, SCALE)
pygame.draw.rect(DISPLAYSURF, DARKSLATEGRAY, (0, 0, WINDOWWIDTH//8, WINDOWHEIGHT), 0)
pygame.draw.line(DISPLAYSURF, GRAY, (WINDOWWIDTH//8, 0), (WINDOWWIDTH//8, WINDOWHEIGHT), 2)
for widget in widgets:
widget.draw(DISPLAYSURF)
L.update(DISPLAYSURF)
grid.draw(DISPLAYSURF)
pygame.display.update()
FPSCLOCK.tick(FPS)
def drawGrid(board, cellWidth, cellHeight, padding, onColor, offColor, offsetX, offsetY):
nRows = len(board)
nCols = len(board[0])
y = offsetY
for row in range(nRows):
x = offsetX
for column in range(nCols):
if board[row][column]!=1:
pygame.draw.rect(DISPLAYSURF, offColor, [x+padding, y+padding, cellWidth, cellHeight],0)
else:
pygame.draw.rect(DISPLAYSURF, onColor, [x+padding, y+padding, cellWidth, cellHeight],0)
x+=(cellWidth+padding)
y+=(cellHeight+padding)
def optionSelected(buttonRectList):
global SIMTYPE
for i in range(len(buttonRectList)):
if buttonRectList[i].collidepoint(pygame.mouse.get_pos()):
SIMTYPE = i
return True
return False
def terminate():
pygame.quit()
sys.exit()
if __name__ == '__main__':
main()
# try:
# main()
# except Exception as e:
# print(str(e))
# terminate()
| python |
''' image '''
import cv2
import numpy as np
def parse_image(f: bytes):
''' parse image '''
nparr = np.frombuffer(f, np.uint8)
return cv2.imdecode(nparr, cv2.IMREAD_COLOR)
def load_image(path: str):
''' load image '''
return cv2.imread(path)
def a_hash(img) -> int:
''' 均值哈希算法 '''
# 缩放为8*8
img = cv2.resize(img, (8, 8))
# 转换为灰度图
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# s为像素和初值为0,hash_str为hash值初值为''
s = 0
ahash = 0
# 遍历累加求像素和
for i in range(8):
for j in range(8):
s = s+gray[i, j]
# 求平均灰度
avg = s/64
# 灰度大于平均值为1相反为0生成图片的hash值
for i in range(8):
for j in range(8):
if gray[i, j] > avg:
ahash += 1 << (j+8*i)
return ahash
def d_hash(img) -> int:
''' 差值哈希算法 '''
# 缩放8*8
img = cv2.resize(img, (9, 8))
# 转换灰度图
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dhash = 0
# 每行前一个像素大于后一个像素为1,相反为0,生成哈希
for i in range(8):
for j in range(8):
if gray[i, j] > gray[i, j+1]:
dhash += 1 << (j+8*i)
return dhash
def p_hash(img) -> int:
''' 感知哈希算法 '''
# 缩放32*32
img = cv2.resize(img, (32, 32)) # , interpolation=cv2.INTER_CUBIC
# 转换为灰度图
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 将灰度图转为浮点型,再进行dct变换
dct = cv2.dct(np.float32(gray))
# opencv实现的掩码操作
dct_roi = dct[0:8, 0:8]
phash = 0
avreage = np.mean(dct_roi)
for i in range(dct_roi.shape[0]):
for j in range(dct_roi.shape[1]):
if dct_roi[i, j] > avreage:
phash += 1 << (j+8*i)
return phash
def hamming(hash1: int, hash2: int) -> int:
''' get hamming distance '''
d = hash1 ^ hash2
result = 0
while d != 0:
result += d & 1
d = d >> 1
return result
def calculate(image1, image2):
''' 灰度直方图算法 '''
# 计算单通道的直方图的相似值
hist1 = cv2.calcHist([image1], [0], None, [256], [0.0, 255.0])
hist2 = cv2.calcHist([image2], [0], None, [256], [0.0, 255.0])
# 计算直方图的重合度
degree = 0
for i in range(len(hist1)):
if hist1[i] != hist2[i]:
degree = degree + \
(1 - abs(hist1[i] - hist2[i]) / max(hist1[i], hist2[i]))
else:
degree = degree + 1
degree = degree / len(hist1)
return degree
| python |
from .tADT_h import TADT_h
from .tClass1_h import TClass1_h
from .tADT_c import TADT_c
from .tMemoryPool_ADT_c import TMemoryPool_ADT_c
| python |
from django.db import models
# This model refers to contact us page in the site
class CoachingContact(models.Model):
username = models.CharField(max_length=100, unique=True, blank=False, default='')
address = models.CharField(max_length=500, default='')
city = models.CharField(max_length=500, default='')
email = models.EmailField(max_length=70, default='')
phone = models.IntegerField(default=0)
message = models.CharField(max_length=500, default='')
header = models.CharField(max_length=200, default='')
# This model refers to course page in the site
class CoachingCourse(models.Model):
username = models.CharField(max_length=100, default='')
title = models.CharField(max_length=500, default='')
chapterid = models.CharField(max_length=50, default='')
courseid = models.IntegerField(default=0)
chapter = models.CharField(max_length=1000, default='')
# This model refers to course page in the site
class CoursePrice(models.Model):
username = models.CharField(max_length=100, default='')
title = models.CharField(max_length=500, default='')
price = models.IntegerField(default=0)
# This model refers to contact us page in the site
class StudentEnquiry(models.Model):
username = models.CharField(max_length=100, default='')
name = models.CharField(max_length=500, default='')
email = models.EmailField(max_length=70, default='')
mobile = models.IntegerField(default=0)
message = models.CharField(max_length=1000, default='')
subject = models.CharField(max_length=500, default='')
created_at = models.DateTimeField(auto_now_add=True)
# This model refers to contact us page in the site
class CoachingAboutus(models.Model):
username = models.CharField(max_length=100, default='')
aboutus = models.CharField(max_length=5000, default='')
aboutteam = models.CharField(max_length=5000, default='')
class CoachingAchievements(models.Model):
username = models.CharField(max_length=100, default='')
title = models.CharField(max_length=500, default='')
achievements = models.CharField(max_length=5000, default='')
class CoachingTeam(models.Model):
username = models.CharField(max_length=100, default='')
name = models.CharField(max_length=100, default='')
designation = models.CharField(max_length=500, default='')
description = models.CharField(max_length=1000, default='')
class CoachingNews(models.Model):
username = models.CharField(max_length=100, default='')
title = models.CharField(max_length=100, default='')
message = models.CharField(max_length=5000, default='')
class CoachingHome(models.Model):
username = models.CharField(max_length=100, default='')
image_txt_1 = models.CharField(max_length=100, default='')
image_txt_2 = models.CharField(max_length=100, default='')
courses = models.CharField(max_length=100, default='')
our_staff = models.CharField(max_length=100, default='')
latest_updates = models.CharField(max_length=100, default='')
placements = models.CharField(max_length=100, default='')
class NewCourses(models.Model):
username = models.CharField(max_length=100, default='')
title = models.CharField(max_length=100, default='')
message = models.CharField(max_length=500, default='')
class Teachers(models.Model):
username = models.CharField(max_length=100, default='')
name = models.CharField(max_length=100, default='')
contact = models.IntegerField(default=0)
email = models.EmailField(max_length=70, default='')
description = models.CharField(max_length=1000, default='') | python |
x = float(input("Enter your first number: "))
y = float(input("Enter your second number: "))
print("The sum of ",x," and ",y, "is equal to ",x+y) | python |
# Copyright 2016 ClusterHQ Inc. See LICENSE file for details.
from zope.interface import implementer
from twisted.internet.defer import succeed
from twisted.internet.task import Clock
from flocker.testtools import TestCase
from benchmark._interfaces import IRequest
from benchmark.scenarios._request_load import RequestLoadScenario
@implementer(IRequest)
class TestRequest:
"""
A very simple request that does nothing but always succeeds.
"""
def run_setup(self):
return succeed(None)
def make_request(self):
return succeed(None)
def run_cleanup(self):
return succeed(None)
class RequestMeasureTests(TestCase):
"""
Tests for ``_request_and_measure``.
"""
def test_single_count(self):
"""
Adds ``request_rate`` samples per call.
"""
calls_per_second = 10
clock = Clock()
request = TestRequest()
scenario = RequestLoadScenario(
clock, request, request_rate=calls_per_second
)
scenario._request_and_measure(1)
self.assertEqual(
scenario.rate_measurer.get_metrics()['ok_count'], calls_per_second
)
def test_multiple_count(self):
"""
The count controls how many requests are made.
"""
calls_per_second = 10
seconds = 2
clock = Clock()
request = TestRequest()
scenario = RequestLoadScenario(
clock, request, request_rate=calls_per_second
)
scenario._request_and_measure(seconds)
self.assertEqual(
scenario.rate_measurer.get_metrics()['ok_count'],
calls_per_second * seconds
)
| python |
# Generated by Django 2.2.7 on 2019-11-16 17:58
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('resource_data', '0004_auto_20191116_2233'),
]
operations = [
migrations.AlterModelOptions(
name='course',
options={'ordering': ('sem', 'course_code')},
),
migrations.AlterModelOptions(
name='teacher',
options={'ordering': ('first_name',)},
),
]
| python |
#!/usr/bin/env python3
import coiled
coiled.create_software_environment(
name="coiled-science-thursdays-itk",
conda="environment.yml",
)
| python |
import sys
import json
import asyncio
import websockets
URI = 'ws://harmony-1.hackable.software:3380/chat'
async def register(ws, name: str) -> str:
await ws.send(json.dumps({'type': 'register', 'displayName': name}))
uid_msg = await ws.recv()
parsed_msg = json.loads(uid_msg)
if not 'uid' in parsed_msg:
print(parsed_msg, name)
return parsed_msg['uid']
def create_channel(name: str) -> str:
return json.dumps({'type': 'new-channel', 'name': name})
def invite(uid: str) -> str:
global cid
return json.dumps({'type': 'invite', 'chId': cid, 'uid': uid})
def message(msg: str) -> str:
global cid
return json.dumps({'type': 'message', 'chId': cid, 'msg': msg})
def parse_line(line: str):
line = line.rstrip()
if line == '':
return ('random_name', '')
parts = line.split(': ')
return (parts[0], ':'.join(parts[1:]))
cid = ''
async def send_line(line: str, main_ws):
global cid
payload_name, payload_msg = parse_line(line)
async with websockets.connect(URI) as ws:
print('Payload WS connected!')
uid = await register(ws, payload_name)
await ws.recv() # welcome message
await main_ws.send(invite(uid))
await main_ws.recv() # "Invited {uname} to channel {cname}."
await ws.recv() # joined message
await ws.send(message(payload_msg))
print(await ws.recv())
async def hello():
global cid
lines = []
with open(sys.argv[1]) as payload:
lines = payload.readlines()
print(lines)
async with websockets.connect(URI) as main_ws:
print('Main WS connected!')
# register main websocket
payload_name, payload_msg = parse_line(lines[0])
uid = await register(main_ws, payload_name)
await main_ws.recv() # welcome message - skip
# create payload channel
await main_ws.send(create_channel('payload'))
joined_msg = await main_ws.recv()
cid = json.loads(joined_msg)['channels'][0]['chId']
# send first line of payload
await main_ws.send(message(payload_msg))
print(await main_ws.recv())
for line in lines[1:]:
await send_line(line, main_ws)
print(f'http://harmony-1.hackable.software:3380/logs/{uid}/{cid}')
asyncio.get_event_loop().run_until_complete(hello())
| python |
#!/usr/bin/env python3
# Picross Puzzle Solver (CLI version)
#
# Author: Ibb Marsh
# Created: 2018-06-25
#
# Description: Accepts a JSON of 2 2D arrays of counts of bit blocks in each row/column.
# Solves for, and then outputs, all grids which fit those constraints.
import sys, argparse, json
from solver_logic import Cell, Block, Line
class PuzzleSolver:
DEFAULT_PARAMS = {
'filename': 'puzzle.json',
}
def __init__ (self, argv):
parser = self.build_parser()
args = parser.parse_args(argv[1:])
self.filename = args.filename
def build_parser (self):
parser = argparse.ArgumentParser(description='Accepts a JSON of 2 2D arrays of counts of '+ \
'bit blocks in each row/column. Solves for, and then outputs, all grids which fit those '+ \
'constraints.')
parser.add_argument('-f','--filename',default=self.DEFAULT_PARAMS['filename'],type=str,
help="Sets input filename (default: {})".format(self.DEFAULT_PARAMS['filename']))
return parser
def run (self):
data = {}
with open(self.filename,'r') as f:
data = json.load(f)
self.base = data['base']
self.width = len(data['cols'])
self.height = len(data['rows'])
self.cells = [[Cell(0,(i,j)) for j in range(self.width)] for i in range(self.height)]
self.cellsT = [[self.cells[i][j] for i in range(self.height)] for j in range(self.width)]
self.rows = [Line(self.cells[k],data['rows'][k]) for k in range(self.height)]
self.cols = [Line(self.cellsT[k],data['cols'][k]) for k in range(self.width)]
if __name__ == '__main__':
ps = PuzzleSolver(sys.argv)
ps.run()
| python |
import time
import numpy
from ..Instruments import EG_G_7265
#from ..Instruments import SRS_SR830
from ..UserInterfaces.Loggers import NullLogger
class VSMController2(object):
#Controlador y sensor del VSM
def __init__(self, Logger = None):
self.LockIn = EG_G_7265(RemoteOnly = False)
#self.LockIn = SRS_SR830(GPIB_Address = 22, RemoteOnly = False)
self.LockIn.InputMode('0')
self.LockIn.VoltageInputMode('1')
self.LockIn.FilterSlope('3')
self.LockIn.setRefPhase(85.0)
self.confDriver()
self.confInput()
self.emu_per_V = 1
#self.emu_per_V = 3.2867
#self.emu_per_V = 1
if Logger == None:
self._logger = NullLogger()
else:
self._logger = Logger
self.log = self._logger.log
def confDriver(self, OscFrec = 200, OscAmp = 0.2):
self.LockIn.setOscilatorAmp(OscAmp)
self.LockIn.setOscilatorFreq(OscFrec)
def confInput(self, Sen = 0.1, TC = 0.1, AcGain = '0'):
self.LockIn.TC = TC
self.LockIn.SEN = Sen
self.LockIn.ConfigureInput(AcGain = AcGain)
def ZeroPhase(self):
TCtemp = self.LockIn.TC
self.LockIn.TC = 1
time.sleep(15)
ph = 0
for i in range(10):
time.sleep(1)
ph = self.LockIn.Phase + ph
ph = ph / 10.0
self.LockIn.setRefPhase(self.LockIn.getRefPhase() + ph)
self.LockIn.TC = TCtemp
time.sleep(3)
def getRefPhase(self):
return self.LockIn.getRefPhase()
def getMagnetization(self, n = 20, iniDelay = 1, measDelay = 0, stat = False, tol = 0.05, maxIts = 50):
self.log('Measuring Magnetization ... ', EOL = '')
vsIn = numpy.zeros(n)
time.sleep(iniDelay)
for i in range(n):
time.sleep(measDelay)
vsIn[i] = self.LockIn.X
vIn = vsIn.mean()
sigma = vsIn.std()
maxSigma = numpy.abs(self.LockIn.SEN * tol)
if stat:
its = 0
while (sigma > maxSigma) and (its < maxIts):
its = its + 1
err = (vsIn - vIn)**2
vsIn = vsIn[err < sigma**2]
while len(vsIn) < n:
time.sleep(measDelay)
vsIn = numpy.append(vsIn, self.LockIn.X)
vIn = vsIn.mean()
sigma = vsIn.std()
self.log('Done.', [125,125,125])
self.log('M = %.3E | ' % (vIn * self.emu_per_V), [100,100,100], EOL = '')
self.log('s = %.3E ' % (sigma * self.emu_per_V), [190,190,190])
return numpy.array([vIn, sigma])* self.emu_per_V
def getAmplitude(self, n = 20, iniDelay = 1, measDelay = 0):
vsIn = numpy.zeros(n)
time.sleep(iniDelay)
for i in range(n):
time.sleep(measDelay)
vsIn[i] = self.LockIn.Magnitude
vIn = vsIn.mean()
return vIn
| python |
# -*- coding: utf-8 -*-
from django.conf.urls import url
from django.views.generic import TemplateView
from . import views
app_name = 'interface'
urlpatterns = [
url(r'^$', views.MainPageView.as_view(), name='main'),
url(r'^game/(?P<uuid>[^/]+)/$', views.GameView.as_view(), name='game'),
url(r'^game/(?P<uuid>[^/]+)/add-player/$', views.AddPlayerView.as_view(),
name='add_player'),
url(r'^game/(?P<uuid>[^/]+)/add-company/$', views.AddCompanyView.as_view(),
name='add_company'),
]
| python |
# -*- coding: utf-8 -*-
"""
Justin Clark
CSYS 300
Final Project
popularityPrediction.py
Use different ML methods to predict song popularity
Outline:
"""
### 1. Imports ###
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
from sklearn import preprocessing
from sklearn.preprocessing import PolynomialFeatures
from sklearn import metrics
from sklearn import datasets
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.feature_selection import RFE
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn import svm
from sklearn import linear_model
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import cross_val_predict
from sklearn.preprocessing import StandardScaler
from collections import Counter
from sklearn.model_selection import RandomizedSearchCV
from sklearn.model_selection import ShuffleSplit
from sklearn.model_selection import learning_curve
from scipy.stats import randint as sp_randint
from sklearn.decomposition import PCA
from sklearn.preprocessing import OneHotEncoder
from sklearn.metrics import confusion_matrix
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegressionCV
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_squared_error
from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import make_regression
from sklearn.tree import DecisionTreeRegressor
from sklearn.feature_selection import SelectFromModel
from sklearn import tree
from mlens.visualization import corrmat
from sklearn.neural_network import MLPRegressor
#data = pd.read_csv('Project/rap_1993-2019.csv')
data = pd.read_csv('rap_1993_2020.csv')
data = data.rename(columns = {'Prop Lines Neg': 'prop_neg',
'Prop Lines Neu': 'prop_neut',
'Prop Lines Pos': 'prop_pos',
'Avg Sentiment': 'avg_sent',
'Year': 'year',
'Word Count': 'word_count',
'Prop Unique Words': 'p_unique'})
data = data[data['popularity'] != 0]
data['class'] = data['popularity']>50
data['class'] = data['class'].astype(int)
Counter(data['class'].tolist())
data.describe().T.iloc[0:14,0:3]
rows = data.shape[0]
cols = data.shape[1]
target_index = data.columns.get_loc("popularity")
X = data.iloc[:,target_index + 1:cols-1]
feature_names = X.columns
Y = data.iloc[:,-1]
X = np.matrix(X)
Y = np.array(Y).T
# Distribution of Target Values
avg_pop = np.mean(Y)
std = np.std(Y)
plt.hist(Y,bins = 50)
plt.text(20,31,"Mean: {:.2f} Std: {:.2f}".format(avg_pop,std),fontsize = 14)
plt.grid(axis = 'y',alpha = 0.75)
plt.xlabel("Target Value: Song Popularity Score",fontsize = 18)
plt.ylabel("Frequency",fontsize = 18)
plt.title("Distribution of Target Values: Song Popularity Scores",fontsize = 18)
plt.show()
#X = preprocessing.standardize(X)
X_train, X_test, y_train, y_test = train_test_split(X,Y,test_size = 0.2,random_state = 1)
#X_train,X_valid,y_train,y_valid = train_test_split(X_train,y_train,test_size = 0.2)
sc = StandardScaler()
X_standardized = sc.fit_transform(X)
X_train_standardized= sc.fit_transform(X_train)
X_test_standardized = sc.fit_transform(X_test)
C_list = [10,1,.1,.001]
for reg_penalty in C_list:
clf = LogisticRegression(penalty = 'l1',C=reg_penalty,solver = 'liblinear')
clf.fit(X_train_standardized,y_train)
feature_importance = clf.coef_[0]
y_pred = clf.predict(X_test_standardized)
confusion_matric = metrics.confusion_matrix(y_test,y_pred)
f1_score = metrics.f1_score(y_test,y_pred)
print("Regularization Pentality: {}".format(reg_penalty))
print("Feature Coefficients: {}".format(clf.coef_))
print("Training Accuracy: {}".format(clf.score(X_train_standardized,y_train)))
print("Testing Accuracy: {}".format(clf.score(X_test_standardized,y_test)))
print("F1 Score: {}".format(f1_score))
for i,v in enumerate(feature_importance):
print("Feature: {} Importancce: {}".format(feature_names[i],v))
print(confusion_matrix)
print(metrics.classification_report(y_test,y_pred))
print(metrics.precision_recall_fscore_support(y_test, y_pred, average='macro'))
AUC = metrics.roc_auc_score(y_test,y_pred)
print("AUC: {}".format(AUC))
print("-"*100)
#######################################
#SVM
#######################################
model = SVC()
model.fit(X_train_standardized,y_train)
y_pred = model.predict(X_test_standardized)
print(metrics.classification_report(y_test,y_pred))
param_grid = {'C': [0.1, 1, 10, 100, 1000],
'gamma': [1, 0.1, 0.01, 0.001, 0.0001],
#'kernel': ['rbf']}
'kernel': ['rbf']}
grid = GridSearchCV(SVC(), param_grid, refit = True, verbose = 3)
grid.fit(X_train, y_train)
print(grid.best_params_)
print(grid.best_estimator_)
grid_predictions = grid.predict(X_test)
print(metrics.classification_report(y_test, grid_predictions))
print(metrics.precision_recall_fscore_support(y_test, grid_predictions, average='macro'))
AUC = metrics.roc_auc_score(y_test,grid_predictions)
print("AUC: {}".format(AUC))
######################################
# Decision Tree / Random Forest
######################################
print("-"*100)
#### Tree based feature selection
forest = ExtraTreesClassifier(n_estimators = 250)
forest.fit(X, Y)
importances = forest.feature_importances_
std = np.std([tree.feature_importances_ for tree in forest.estimators_],
axis=0)
indices = np.argsort(importances)
# Plot the feature importances of the forest
plt.figure()
plt.title("Extra Classifers: Feature Importances")
plt.barh(range(X.shape[1]), importances[indices],
color="grey",edgecolor = 'black', xerr=std[indices],ecolor = 'black', align="center")
# If you want to define your own labels,
# change indices to a list of labels on the following line.
plt.yticks(range(X.shape[1]), feature_names[indices])
plt.ylim([-1, X.shape[1]])
plt.tight_layout()
plt.savefig(os.getcwd() + '/Plots/feature_importance_tree.png',dpi = 900)
plt.show()
# display the relative importance of each attribute
print(forest.feature_importances_)
model = SelectFromModel(forest,prefit = True)
X_feature_selection = model.transform(X)
print(X_feature_selection.shape)
print("-"*100)
Xf_train, Xf_test, yf_train, yf_test = train_test_split(X_feature_selection,Y,test_size = 0.2,random_state = 1)
#Single Decision Tree: No Feature Selection
clf = DecisionTreeClassifier()
clf.fit(X_train_standardized,y_train)
y_pred = clf.predict(X_test_standardized)
print("Single Decision tree")
print(metrics.classification_report(y_test,y_pred))
f1_score = metrics.f1_score(y_test,y_pred)
print(metrics.precision_recall_fscore_support(y_test, y_pred, average='macro'))
print("F1 Score: {}".format(f1_score))
AUC = metrics.roc_auc_score(y_test,y_pred)
print("AUC: {}".format(AUC))
print("-"*100)
# Single Decision Tree: Feature Selection
clf = DecisionTreeClassifier()
clf.fit(Xf_train,yf_train)
y_pred = clf.predict(Xf_test)
print("Single Decision tree:Feature Selection")
print(metrics.classification_report(yf_test,y_pred))
f1_score = metrics.f1_score(y_test,y_pred)
print("F1 Score: {}".format(f1_score))
print(metrics.precision_recall_fscore_support(y_test, y_pred, average='macro'))
AUC = metrics.roc_auc_score(y_test,y_pred)
print("AUC: {}".format(AUC))
print("-"*100)
# Random Forest: No Feature Selection
num_trees = 1000
clf = RandomForestClassifier(n_estimators = num_trees,bootstrap = True,max_features = 'sqrt')
clf.fit(X_train_standardized,y_train)
y_pred = clf.predict(X_test_standardized)
print("Random Forest")
print(metrics.classification_report(y_test,y_pred))
f1_score = metrics.f1_score(y_test,y_pred)
print("F1 Score: {}".format(f1_score))
print(metrics.precision_recall_fscore_support(y_test, y_pred, average='macro'))
AUC = metrics.roc_auc_score(y_test,y_pred)
print("AUC: {}".format(AUC))
print("-"*100)
# Random Forest: Feature Selection
print("Random Forest:Feature Selection")
clf = RandomForestClassifier(n_estimators = num_trees,bootstrap = True,max_features = 'sqrt')
clf.fit(Xf_train,yf_train)
y_pred = clf.predict(Xf_test)
print(metrics.classification_report(yf_test,y_pred))
f1_score = metrics.f1_score(y_test,y_pred)
print("F1 Score: {}".format(f1_score))
print(metrics.precision_recall_fscore_support(y_test, y_pred, average='macro'))
AUC = metrics.roc_auc_score(y_test,y_pred)
print("AUC: {}".format(AUC))
print("-"*100)
| python |
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: dm.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf.internal import enum_type_wrapper
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='dm.proto',
package='bilibili.community.service.dm.v1',
syntax='proto3',
serialized_options=None,
serialized_pb=_b('\n\x08\x64m.proto\x12 bilibili.community.service.dm.v1\"L\n\x0b\x44mSegSDKReq\x12\x0b\n\x03pid\x18\x01 \x01(\x03\x12\x0b\n\x03oid\x18\x02 \x01(\x03\x12\x0c\n\x04type\x18\x03 \x01(\x05\x12\x15\n\rsegment_index\x18\x04 \x01(\x03\"]\n\rDmSegSDKReply\x12\x0e\n\x06\x63losed\x18\x01 \x01(\x08\x12<\n\x05\x65lems\x18\x02 \x03(\x0b\x32-.bilibili.community.service.dm.v1.DanmakuElem\"L\n\x0b\x44mSegOttReq\x12\x0b\n\x03pid\x18\x01 \x01(\x03\x12\x0b\n\x03oid\x18\x02 \x01(\x03\x12\x0c\n\x04type\x18\x03 \x01(\x05\x12\x15\n\rsegment_index\x18\x04 \x01(\x03\"]\n\rDmSegOttReply\x12\x0e\n\x06\x63losed\x18\x01 \x01(\x08\x12<\n\x05\x65lems\x18\x02 \x03(\x0b\x32-.bilibili.community.service.dm.v1.DanmakuElem\"g\n\x0e\x44mSegMobileReq\x12\x0b\n\x03pid\x18\x01 \x01(\x03\x12\x0b\n\x03oid\x18\x02 \x01(\x03\x12\x0c\n\x04type\x18\x03 \x01(\x05\x12\x15\n\rsegment_index\x18\x04 \x01(\x03\x12\x16\n\x0eteenagers_mode\x18\x05 \x01(\x05\"\xa1\x01\n\x10\x44mSegMobileReply\x12<\n\x05\x65lems\x18\x01 \x03(\x0b\x32-.bilibili.community.service.dm.v1.DanmakuElem\x12\r\n\x05state\x18\x02 \x01(\x05\x12@\n\x07\x61i_flag\x18\x03 \x01(\x0b\x32/.bilibili.community.service.dm.v1.DanmakuAIFlag\"X\n\tDmViewReq\x12\x0b\n\x03pid\x18\x01 \x01(\x03\x12\x0b\n\x03oid\x18\x02 \x01(\x03\x12\x0c\n\x04type\x18\x03 \x01(\x05\x12\r\n\x05spmid\x18\x04 \x01(\t\x12\x14\n\x0cis_hard_boot\x18\x05 \x01(\x05\"\xf0\x03\n\x0b\x44mViewReply\x12\x0e\n\x06\x63losed\x18\x01 \x01(\x08\x12\x39\n\x04mask\x18\x02 \x01(\x0b\x32+.bilibili.community.service.dm.v1.VideoMask\x12\x41\n\x08subtitle\x18\x03 \x01(\x0b\x32/.bilibili.community.service.dm.v1.VideoSubtitle\x12\x13\n\x0bspecial_dms\x18\x04 \x03(\t\x12\x44\n\x07\x61i_flag\x18\x05 \x01(\x0b\x32\x33.bilibili.community.service.dm.v1.DanmakuFlagConfig\x12N\n\rplayer_config\x18\x06 \x01(\x0b\x32\x37.bilibili.community.service.dm.v1.DanmuPlayerViewConfig\x12\x16\n\x0esend_box_style\x18\x07 \x01(\x05\x12\r\n\x05\x61llow\x18\x08 \x01(\x08\x12\x11\n\tcheck_box\x18\t \x01(\t\x12\x1a\n\x12\x63heck_box_show_msg\x18\n \x01(\t\x12\x18\n\x10text_placeholder\x18\x0b \x01(\t\x12\x19\n\x11input_placeholder\x18\x0c \x01(\t\x12\x1d\n\x15report_filter_content\x18\r \x03(\t\"\xa8\x03\n\x0e\x44mWebViewReply\x12\r\n\x05state\x18\x01 \x01(\x05\x12\x0c\n\x04text\x18\x02 \x01(\t\x12\x11\n\ttext_side\x18\x03 \x01(\t\x12=\n\x06\x64m_sge\x18\x04 \x01(\x0b\x32-.bilibili.community.service.dm.v1.DmSegConfig\x12\x41\n\x04\x66lag\x18\x05 \x01(\x0b\x32\x33.bilibili.community.service.dm.v1.DanmakuFlagConfig\x12\x13\n\x0bspecial_dms\x18\x06 \x03(\t\x12\x11\n\tcheck_box\x18\x07 \x01(\x08\x12\r\n\x05\x63ount\x18\x08 \x01(\x03\x12?\n\ncommandDms\x18\t \x03(\x0b\x32+.bilibili.community.service.dm.v1.CommandDm\x12M\n\rplayer_config\x18\n \x01(\x0b\x32\x36.bilibili.community.service.dm.v1.DanmuWebPlayerConfig\x12\x1d\n\x15report_filter_content\x18\x0b \x03(\t\"\xa1\x01\n\tCommandDm\x12\n\n\x02id\x18\x01 \x01(\x03\x12\x0b\n\x03oid\x18\x02 \x01(\x03\x12\x0b\n\x03mid\x18\x03 \x01(\t\x12\x0f\n\x07\x63ommand\x18\x04 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x05 \x01(\t\x12\x10\n\x08progress\x18\x06 \x01(\x05\x12\r\n\x05\x63time\x18\x07 \x01(\t\x12\r\n\x05mtime\x18\x08 \x01(\t\x12\r\n\x05\x65xtra\x18\t \x01(\t\x12\r\n\x05idStr\x18\n \x01(\t\"/\n\x0b\x44mSegConfig\x12\x11\n\tpage_size\x18\x01 \x01(\x03\x12\r\n\x05total\x18\x02 \x01(\x03\"S\n\tVideoMask\x12\x0b\n\x03\x63id\x18\x01 \x01(\x03\x12\x0c\n\x04plat\x18\x02 \x01(\x05\x12\x0b\n\x03\x66ps\x18\x03 \x01(\x05\x12\x0c\n\x04time\x18\x04 \x01(\x03\x12\x10\n\x08mask_url\x18\x05 \x01(\t\"o\n\rVideoSubtitle\x12\x0b\n\x03lan\x18\x01 \x01(\t\x12\x0e\n\x06lanDoc\x18\x02 \x01(\t\x12\x41\n\tsubtitles\x18\x03 \x03(\x0b\x32..bilibili.community.service.dm.v1.SubtitleItem\"\x8f\x03\n\x14\x44\x61nmuWebPlayerConfig\x12\x11\n\tdm_switch\x18\x01 \x01(\x08\x12\x11\n\tai_switch\x18\x02 \x01(\x08\x12\x10\n\x08\x61i_level\x18\x03 \x01(\x05\x12\x10\n\x08\x62locktop\x18\x04 \x01(\x08\x12\x13\n\x0b\x62lockscroll\x18\x05 \x01(\x08\x12\x13\n\x0b\x62lockbottom\x18\x06 \x01(\x08\x12\x12\n\nblockcolor\x18\x07 \x01(\x08\x12\x14\n\x0c\x62lockspecial\x18\x08 \x01(\x08\x12\x14\n\x0cpreventshade\x18\t \x01(\x08\x12\r\n\x05\x64mask\x18\n \x01(\x08\x12\x0f\n\x07opacity\x18\x0b \x01(\x02\x12\x0e\n\x06\x64marea\x18\x0c \x01(\x05\x12\x11\n\tspeedplus\x18\r \x01(\x02\x12\x10\n\x08\x66ontsize\x18\x0e \x01(\x02\x12\x12\n\nscreensync\x18\x0f \x01(\x08\x12\x11\n\tspeedsync\x18\x10 \x01(\x08\x12\x12\n\nfontfamily\x18\x11 \x01(\t\x12\x0c\n\x04\x62old\x18\x12 \x01(\x08\x12\x12\n\nfontborder\x18\x13 \x01(\x05\x12\x11\n\tdraw_type\x18\x14 \x01(\t\"\x9a\x01\n\x0cSubtitleItem\x12\n\n\x02id\x18\x01 \x01(\x03\x12\x0e\n\x06id_str\x18\x02 \x01(\t\x12\x0b\n\x03lan\x18\x03 \x01(\t\x12\x0f\n\x07lan_doc\x18\x04 \x01(\t\x12\x14\n\x0csubtitle_url\x18\x05 \x01(\t\x12:\n\x06\x61uthor\x18\x06 \x01(\x0b\x32*.bilibili.community.service.dm.v1.UserInfo\"\\\n\x08UserInfo\x12\x0b\n\x03mid\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x0b\n\x03sex\x18\x03 \x01(\t\x12\x0c\n\x04\x66\x61\x63\x65\x18\x04 \x01(\t\x12\x0c\n\x04sign\x18\x05 \x01(\t\x12\x0c\n\x04rank\x18\x06 \x01(\x05\"\xd6\x01\n\x0b\x44\x61nmakuElem\x12\n\n\x02id\x18\x01 \x01(\x03\x12\x10\n\x08progress\x18\x02 \x01(\x05\x12\x0c\n\x04mode\x18\x03 \x01(\x05\x12\x10\n\x08\x66ontsize\x18\x04 \x01(\x05\x12\r\n\x05\x63olor\x18\x05 \x01(\r\x12\x0f\n\x07midHash\x18\x06 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x07 \x01(\t\x12\r\n\x05\x63time\x18\x08 \x01(\x03\x12\x0e\n\x06weight\x18\t \x01(\x05\x12\x0e\n\x06\x61\x63tion\x18\n \x01(\t\x12\x0c\n\x04pool\x18\x0b \x01(\x05\x12\r\n\x05idStr\x18\x0c \x01(\t\x12\x0c\n\x04\x61ttr\x18\r \x01(\x05\"\xa0\x0b\n\x11\x44mPlayerConfigReq\x12\n\n\x02ts\x18\x01 \x01(\x03\x12\x45\n\x06switch\x18\x02 \x01(\x0b\x32\x35.bilibili.community.service.dm.v1.PlayerDanmakuSwitch\x12N\n\x0bswitch_save\x18\x03 \x01(\x0b\x32\x39.bilibili.community.service.dm.v1.PlayerDanmakuSwitchSave\x12[\n\x12use_default_config\x18\x04 \x01(\x0b\x32?.bilibili.community.service.dm.v1.PlayerDanmakuUseDefaultConfig\x12\x61\n\x15\x61i_recommended_switch\x18\x05 \x01(\x0b\x32\x42.bilibili.community.service.dm.v1.PlayerDanmakuAiRecommendedSwitch\x12_\n\x14\x61i_recommended_level\x18\x06 \x01(\x0b\x32\x41.bilibili.community.service.dm.v1.PlayerDanmakuAiRecommendedLevel\x12I\n\x08\x62locktop\x18\x07 \x01(\x0b\x32\x37.bilibili.community.service.dm.v1.PlayerDanmakuBlocktop\x12O\n\x0b\x62lockscroll\x18\x08 \x01(\x0b\x32:.bilibili.community.service.dm.v1.PlayerDanmakuBlockscroll\x12O\n\x0b\x62lockbottom\x18\t \x01(\x0b\x32:.bilibili.community.service.dm.v1.PlayerDanmakuBlockbottom\x12S\n\rblockcolorful\x18\n \x01(\x0b\x32<.bilibili.community.service.dm.v1.PlayerDanmakuBlockcolorful\x12O\n\x0b\x62lockrepeat\x18\x0b \x01(\x0b\x32:.bilibili.community.service.dm.v1.PlayerDanmakuBlockrepeat\x12Q\n\x0c\x62lockspecial\x18\x0c \x01(\x0b\x32;.bilibili.community.service.dm.v1.PlayerDanmakuBlockspecial\x12G\n\x07opacity\x18\r \x01(\x0b\x32\x36.bilibili.community.service.dm.v1.PlayerDanmakuOpacity\x12S\n\rscalingfactor\x18\x0e \x01(\x0b\x32<.bilibili.community.service.dm.v1.PlayerDanmakuScalingfactor\x12\x45\n\x06\x64omain\x18\x0f \x01(\x0b\x32\x35.bilibili.community.service.dm.v1.PlayerDanmakuDomain\x12\x43\n\x05speed\x18\x10 \x01(\x0b\x32\x34.bilibili.community.service.dm.v1.PlayerDanmakuSpeed\x12W\n\x0f\x65nableblocklist\x18\x11 \x01(\x0b\x32>.bilibili.community.service.dm.v1.PlayerDanmakuEnableblocklist\x12^\n\x19inlinePlayerDanmakuSwitch\x18\x12 \x01(\x0b\x32;.bilibili.community.service.dm.v1.InlinePlayerDanmakuSwitch\")\n\x08Response\x12\x0c\n\x04\x63ode\x18\x01 \x01(\x05\x12\x0f\n\x07message\x18\x02 \x01(\t\")\n\x0b\x44\x61nmakuFlag\x12\x0c\n\x04\x64mid\x18\x01 \x01(\x03\x12\x0c\n\x04\x66lag\x18\x02 \x01(\r\"K\n\x11\x44\x61nmakuFlagConfig\x12\x10\n\x08rec_flag\x18\x01 \x01(\x05\x12\x10\n\x08rec_text\x18\x02 \x01(\t\x12\x12\n\nrec_switch\x18\x03 \x01(\x05\"P\n\rDanmakuAIFlag\x12?\n\x08\x64m_flags\x18\x01 \x03(\x0b\x32-.bilibili.community.service.dm.v1.DanmakuFlag\"\xb1\x02\n\x15\x44\x61nmuPlayerViewConfig\x12\x61\n\x1d\x64\x61nmuku_default_player_config\x18\x01 \x01(\x0b\x32:.bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig\x12R\n\x15\x64\x61nmuku_player_config\x18\x02 \x01(\x0b\x32\x33.bilibili.community.service.dm.v1.DanmuPlayerConfig\x12\x61\n\x1d\x64\x61nmuku_player_dynamic_config\x18\x03 \x03(\x0b\x32:.bilibili.community.service.dm.v1.DanmuPlayerDynamicConfig\"\xa1\x04\n\x18\x44\x61nmuDefaultPlayerConfig\x12)\n!player_danmaku_use_default_config\x18\x01 \x01(\x08\x12,\n$player_danmaku_ai_recommended_switch\x18\x04 \x01(\x08\x12+\n#player_danmaku_ai_recommended_level\x18\x05 \x01(\x05\x12\x1f\n\x17player_danmaku_blocktop\x18\x06 \x01(\x08\x12\"\n\x1aplayer_danmaku_blockscroll\x18\x07 \x01(\x08\x12\"\n\x1aplayer_danmaku_blockbottom\x18\x08 \x01(\x08\x12$\n\x1cplayer_danmaku_blockcolorful\x18\t \x01(\x08\x12\"\n\x1aplayer_danmaku_blockrepeat\x18\n \x01(\x08\x12#\n\x1bplayer_danmaku_blockspecial\x18\x0b \x01(\x08\x12\x1e\n\x16player_danmaku_opacity\x18\x0c \x01(\x02\x12$\n\x1cplayer_danmaku_scalingfactor\x18\r \x01(\x02\x12\x1d\n\x15player_danmaku_domain\x18\x0e \x01(\x02\x12\x1c\n\x14player_danmaku_speed\x18\x0f \x01(\x05\x12$\n\x1cinline_player_danmaku_switch\x18\x10 \x01(\x08\"\xab\x05\n\x11\x44\x61nmuPlayerConfig\x12\x1d\n\x15player_danmaku_switch\x18\x01 \x01(\x08\x12\"\n\x1aplayer_danmaku_switch_save\x18\x02 \x01(\x08\x12)\n!player_danmaku_use_default_config\x18\x03 \x01(\x08\x12,\n$player_danmaku_ai_recommended_switch\x18\x04 \x01(\x08\x12+\n#player_danmaku_ai_recommended_level\x18\x05 \x01(\x05\x12\x1f\n\x17player_danmaku_blocktop\x18\x06 \x01(\x08\x12\"\n\x1aplayer_danmaku_blockscroll\x18\x07 \x01(\x08\x12\"\n\x1aplayer_danmaku_blockbottom\x18\x08 \x01(\x08\x12$\n\x1cplayer_danmaku_blockcolorful\x18\t \x01(\x08\x12\"\n\x1aplayer_danmaku_blockrepeat\x18\n \x01(\x08\x12#\n\x1bplayer_danmaku_blockspecial\x18\x0b \x01(\x08\x12\x1e\n\x16player_danmaku_opacity\x18\x0c \x01(\x02\x12$\n\x1cplayer_danmaku_scalingfactor\x18\r \x01(\x02\x12\x1d\n\x15player_danmaku_domain\x18\x0e \x01(\x02\x12\x1c\n\x14player_danmaku_speed\x18\x0f \x01(\x05\x12&\n\x1eplayer_danmaku_enableblocklist\x18\x10 \x01(\x08\x12$\n\x1cinline_player_danmaku_switch\x18\x11 \x01(\x08\x12$\n\x1cinline_player_danmaku_config\x18\x12 \x01(\x05\"K\n\x18\x44\x61nmuPlayerDynamicConfig\x12\x10\n\x08progress\x18\x01 \x01(\x05\x12\x1d\n\x15player_danmaku_domain\x18\x02 \x01(\x02\"7\n\x13PlayerDanmakuSwitch\x12\r\n\x05value\x18\x01 \x01(\x08\x12\x11\n\tcanIgnore\x18\x02 \x01(\x08\"(\n\x17PlayerDanmakuSwitchSave\x12\r\n\x05value\x18\x01 \x01(\x08\".\n\x1dPlayerDanmakuUseDefaultConfig\x12\r\n\x05value\x18\x01 \x01(\x08\"1\n PlayerDanmakuAiRecommendedSwitch\x12\r\n\x05value\x18\x01 \x01(\x08\"0\n\x1fPlayerDanmakuAiRecommendedLevel\x12\r\n\x05value\x18\x01 \x01(\x08\"&\n\x15PlayerDanmakuBlocktop\x12\r\n\x05value\x18\x01 \x01(\x08\")\n\x18PlayerDanmakuBlockscroll\x12\r\n\x05value\x18\x01 \x01(\x08\")\n\x18PlayerDanmakuBlockbottom\x12\r\n\x05value\x18\x01 \x01(\x08\"+\n\x1aPlayerDanmakuBlockcolorful\x12\r\n\x05value\x18\x01 \x01(\x08\")\n\x18PlayerDanmakuBlockrepeat\x12\r\n\x05value\x18\x01 \x01(\x08\"*\n\x19PlayerDanmakuBlockspecial\x12\r\n\x05value\x18\x01 \x01(\x08\"%\n\x14PlayerDanmakuOpacity\x12\r\n\x05value\x18\x01 \x01(\x02\"+\n\x1aPlayerDanmakuScalingfactor\x12\r\n\x05value\x18\x01 \x01(\x02\"$\n\x13PlayerDanmakuDomain\x12\r\n\x05value\x18\x01 \x01(\x02\"#\n\x12PlayerDanmakuSpeed\x12\r\n\x05value\x18\x01 \x01(\x05\"-\n\x1cPlayerDanmakuEnableblocklist\x12\r\n\x05value\x18\x01 \x01(\x08\"*\n\x19InlinePlayerDanmakuSwitch\x12\r\n\x05value\x18\x01 \x01(\x08*L\n\tDMAttrBit\x12\x14\n\x10\x44MAttrBitProtect\x10\x00\x12\x15\n\x11\x44MAttrBitFromLive\x10\x01\x12\x12\n\x0e\x44MAttrHighLike\x10\x02\x32\xaa\x04\n\x02\x44M\x12s\n\x0b\x44mSegMobile\x12\x30.bilibili.community.service.dm.v1.DmSegMobileReq\x1a\x32.bilibili.community.service.dm.v1.DmSegMobileReply\x12\x64\n\x06\x44mView\x12+.bilibili.community.service.dm.v1.DmViewReq\x1a-.bilibili.community.service.dm.v1.DmViewReply\x12q\n\x0e\x44mPlayerConfig\x12\x33.bilibili.community.service.dm.v1.DmPlayerConfigReq\x1a*.bilibili.community.service.dm.v1.Response\x12j\n\x08\x44mSegOtt\x12-.bilibili.community.service.dm.v1.DmSegOttReq\x1a/.bilibili.community.service.dm.v1.DmSegOttReply\x12j\n\x08\x44mSegSDK\x12-.bilibili.community.service.dm.v1.DmSegSDKReq\x1a/.bilibili.community.service.dm.v1.DmSegSDKReplyb\x06proto3')
)
_DMATTRBIT = _descriptor.EnumDescriptor(
name='DMAttrBit',
full_name='bilibili.community.service.dm.v1.DMAttrBit',
filename=None,
file=DESCRIPTOR,
values=[
_descriptor.EnumValueDescriptor(
name='DMAttrBitProtect', index=0, number=0,
serialized_options=None,
type=None),
_descriptor.EnumValueDescriptor(
name='DMAttrBitFromLive', index=1, number=1,
serialized_options=None,
type=None),
_descriptor.EnumValueDescriptor(
name='DMAttrHighLike', index=2, number=2,
serialized_options=None,
type=None),
],
containing_type=None,
serialized_options=None,
serialized_start=7021,
serialized_end=7097,
)
_sym_db.RegisterEnumDescriptor(_DMATTRBIT)
DMAttrBit = enum_type_wrapper.EnumTypeWrapper(_DMATTRBIT)
DMAttrBitProtect = 0
DMAttrBitFromLive = 1
DMAttrHighLike = 2
_DMSEGSDKREQ = _descriptor.Descriptor(
name='DmSegSDKReq',
full_name='bilibili.community.service.dm.v1.DmSegSDKReq',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='pid', full_name='bilibili.community.service.dm.v1.DmSegSDKReq.pid', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='oid', full_name='bilibili.community.service.dm.v1.DmSegSDKReq.oid', index=1,
number=2, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='type', full_name='bilibili.community.service.dm.v1.DmSegSDKReq.type', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='segment_index', full_name='bilibili.community.service.dm.v1.DmSegSDKReq.segment_index', index=3,
number=4, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=46,
serialized_end=122,
)
_DMSEGSDKREPLY = _descriptor.Descriptor(
name='DmSegSDKReply',
full_name='bilibili.community.service.dm.v1.DmSegSDKReply',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='closed', full_name='bilibili.community.service.dm.v1.DmSegSDKReply.closed', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='elems', full_name='bilibili.community.service.dm.v1.DmSegSDKReply.elems', index=1,
number=2, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=124,
serialized_end=217,
)
_DMSEGOTTREQ = _descriptor.Descriptor(
name='DmSegOttReq',
full_name='bilibili.community.service.dm.v1.DmSegOttReq',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='pid', full_name='bilibili.community.service.dm.v1.DmSegOttReq.pid', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='oid', full_name='bilibili.community.service.dm.v1.DmSegOttReq.oid', index=1,
number=2, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='type', full_name='bilibili.community.service.dm.v1.DmSegOttReq.type', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='segment_index', full_name='bilibili.community.service.dm.v1.DmSegOttReq.segment_index', index=3,
number=4, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=219,
serialized_end=295,
)
_DMSEGOTTREPLY = _descriptor.Descriptor(
name='DmSegOttReply',
full_name='bilibili.community.service.dm.v1.DmSegOttReply',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='closed', full_name='bilibili.community.service.dm.v1.DmSegOttReply.closed', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='elems', full_name='bilibili.community.service.dm.v1.DmSegOttReply.elems', index=1,
number=2, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=297,
serialized_end=390,
)
_DMSEGMOBILEREQ = _descriptor.Descriptor(
name='DmSegMobileReq',
full_name='bilibili.community.service.dm.v1.DmSegMobileReq',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='pid', full_name='bilibili.community.service.dm.v1.DmSegMobileReq.pid', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='oid', full_name='bilibili.community.service.dm.v1.DmSegMobileReq.oid', index=1,
number=2, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='type', full_name='bilibili.community.service.dm.v1.DmSegMobileReq.type', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='segment_index', full_name='bilibili.community.service.dm.v1.DmSegMobileReq.segment_index', index=3,
number=4, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='teenagers_mode', full_name='bilibili.community.service.dm.v1.DmSegMobileReq.teenagers_mode', index=4,
number=5, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=392,
serialized_end=495,
)
_DMSEGMOBILEREPLY = _descriptor.Descriptor(
name='DmSegMobileReply',
full_name='bilibili.community.service.dm.v1.DmSegMobileReply',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='elems', full_name='bilibili.community.service.dm.v1.DmSegMobileReply.elems', index=0,
number=1, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='state', full_name='bilibili.community.service.dm.v1.DmSegMobileReply.state', index=1,
number=2, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='ai_flag', full_name='bilibili.community.service.dm.v1.DmSegMobileReply.ai_flag', index=2,
number=3, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=498,
serialized_end=659,
)
_DMVIEWREQ = _descriptor.Descriptor(
name='DmViewReq',
full_name='bilibili.community.service.dm.v1.DmViewReq',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='pid', full_name='bilibili.community.service.dm.v1.DmViewReq.pid', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='oid', full_name='bilibili.community.service.dm.v1.DmViewReq.oid', index=1,
number=2, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='type', full_name='bilibili.community.service.dm.v1.DmViewReq.type', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='spmid', full_name='bilibili.community.service.dm.v1.DmViewReq.spmid', index=3,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='is_hard_boot', full_name='bilibili.community.service.dm.v1.DmViewReq.is_hard_boot', index=4,
number=5, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=661,
serialized_end=749,
)
_DMVIEWREPLY = _descriptor.Descriptor(
name='DmViewReply',
full_name='bilibili.community.service.dm.v1.DmViewReply',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='closed', full_name='bilibili.community.service.dm.v1.DmViewReply.closed', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='mask', full_name='bilibili.community.service.dm.v1.DmViewReply.mask', index=1,
number=2, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='subtitle', full_name='bilibili.community.service.dm.v1.DmViewReply.subtitle', index=2,
number=3, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='special_dms', full_name='bilibili.community.service.dm.v1.DmViewReply.special_dms', index=3,
number=4, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='ai_flag', full_name='bilibili.community.service.dm.v1.DmViewReply.ai_flag', index=4,
number=5, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_config', full_name='bilibili.community.service.dm.v1.DmViewReply.player_config', index=5,
number=6, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='send_box_style', full_name='bilibili.community.service.dm.v1.DmViewReply.send_box_style', index=6,
number=7, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='allow', full_name='bilibili.community.service.dm.v1.DmViewReply.allow', index=7,
number=8, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='check_box', full_name='bilibili.community.service.dm.v1.DmViewReply.check_box', index=8,
number=9, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='check_box_show_msg', full_name='bilibili.community.service.dm.v1.DmViewReply.check_box_show_msg', index=9,
number=10, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='text_placeholder', full_name='bilibili.community.service.dm.v1.DmViewReply.text_placeholder', index=10,
number=11, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='input_placeholder', full_name='bilibili.community.service.dm.v1.DmViewReply.input_placeholder', index=11,
number=12, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='report_filter_content', full_name='bilibili.community.service.dm.v1.DmViewReply.report_filter_content', index=12,
number=13, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=752,
serialized_end=1248,
)
_DMWEBVIEWREPLY = _descriptor.Descriptor(
name='DmWebViewReply',
full_name='bilibili.community.service.dm.v1.DmWebViewReply',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='state', full_name='bilibili.community.service.dm.v1.DmWebViewReply.state', index=0,
number=1, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='text', full_name='bilibili.community.service.dm.v1.DmWebViewReply.text', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='text_side', full_name='bilibili.community.service.dm.v1.DmWebViewReply.text_side', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='dm_sge', full_name='bilibili.community.service.dm.v1.DmWebViewReply.dm_sge', index=3,
number=4, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='flag', full_name='bilibili.community.service.dm.v1.DmWebViewReply.flag', index=4,
number=5, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='special_dms', full_name='bilibili.community.service.dm.v1.DmWebViewReply.special_dms', index=5,
number=6, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='check_box', full_name='bilibili.community.service.dm.v1.DmWebViewReply.check_box', index=6,
number=7, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='count', full_name='bilibili.community.service.dm.v1.DmWebViewReply.count', index=7,
number=8, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='commandDms', full_name='bilibili.community.service.dm.v1.DmWebViewReply.commandDms', index=8,
number=9, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_config', full_name='bilibili.community.service.dm.v1.DmWebViewReply.player_config', index=9,
number=10, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='report_filter_content', full_name='bilibili.community.service.dm.v1.DmWebViewReply.report_filter_content', index=10,
number=11, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=1251,
serialized_end=1675,
)
_COMMANDDM = _descriptor.Descriptor(
name='CommandDm',
full_name='bilibili.community.service.dm.v1.CommandDm',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='id', full_name='bilibili.community.service.dm.v1.CommandDm.id', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='oid', full_name='bilibili.community.service.dm.v1.CommandDm.oid', index=1,
number=2, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='mid', full_name='bilibili.community.service.dm.v1.CommandDm.mid', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='command', full_name='bilibili.community.service.dm.v1.CommandDm.command', index=3,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='content', full_name='bilibili.community.service.dm.v1.CommandDm.content', index=4,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='progress', full_name='bilibili.community.service.dm.v1.CommandDm.progress', index=5,
number=6, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='ctime', full_name='bilibili.community.service.dm.v1.CommandDm.ctime', index=6,
number=7, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='mtime', full_name='bilibili.community.service.dm.v1.CommandDm.mtime', index=7,
number=8, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='extra', full_name='bilibili.community.service.dm.v1.CommandDm.extra', index=8,
number=9, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='idStr', full_name='bilibili.community.service.dm.v1.CommandDm.idStr', index=9,
number=10, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=1678,
serialized_end=1839,
)
_DMSEGCONFIG = _descriptor.Descriptor(
name='DmSegConfig',
full_name='bilibili.community.service.dm.v1.DmSegConfig',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='page_size', full_name='bilibili.community.service.dm.v1.DmSegConfig.page_size', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='total', full_name='bilibili.community.service.dm.v1.DmSegConfig.total', index=1,
number=2, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=1841,
serialized_end=1888,
)
_VIDEOMASK = _descriptor.Descriptor(
name='VideoMask',
full_name='bilibili.community.service.dm.v1.VideoMask',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='cid', full_name='bilibili.community.service.dm.v1.VideoMask.cid', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='plat', full_name='bilibili.community.service.dm.v1.VideoMask.plat', index=1,
number=2, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='fps', full_name='bilibili.community.service.dm.v1.VideoMask.fps', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='time', full_name='bilibili.community.service.dm.v1.VideoMask.time', index=3,
number=4, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='mask_url', full_name='bilibili.community.service.dm.v1.VideoMask.mask_url', index=4,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=1890,
serialized_end=1973,
)
_VIDEOSUBTITLE = _descriptor.Descriptor(
name='VideoSubtitle',
full_name='bilibili.community.service.dm.v1.VideoSubtitle',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='lan', full_name='bilibili.community.service.dm.v1.VideoSubtitle.lan', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='lanDoc', full_name='bilibili.community.service.dm.v1.VideoSubtitle.lanDoc', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='subtitles', full_name='bilibili.community.service.dm.v1.VideoSubtitle.subtitles', index=2,
number=3, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=1975,
serialized_end=2086,
)
_DANMUWEBPLAYERCONFIG = _descriptor.Descriptor(
name='DanmuWebPlayerConfig',
full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='dm_switch', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.dm_switch', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='ai_switch', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.ai_switch', index=1,
number=2, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='ai_level', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.ai_level', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blocktop', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.blocktop', index=3,
number=4, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blockscroll', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.blockscroll', index=4,
number=5, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blockbottom', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.blockbottom', index=5,
number=6, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blockcolor', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.blockcolor', index=6,
number=7, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blockspecial', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.blockspecial', index=7,
number=8, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='preventshade', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.preventshade', index=8,
number=9, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='dmask', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.dmask', index=9,
number=10, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='opacity', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.opacity', index=10,
number=11, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='dmarea', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.dmarea', index=11,
number=12, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='speedplus', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.speedplus', index=12,
number=13, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='fontsize', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.fontsize', index=13,
number=14, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='screensync', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.screensync', index=14,
number=15, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='speedsync', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.speedsync', index=15,
number=16, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='fontfamily', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.fontfamily', index=16,
number=17, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='bold', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.bold', index=17,
number=18, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='fontborder', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.fontborder', index=18,
number=19, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='draw_type', full_name='bilibili.community.service.dm.v1.DanmuWebPlayerConfig.draw_type', index=19,
number=20, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=2089,
serialized_end=2488,
)
_SUBTITLEITEM = _descriptor.Descriptor(
name='SubtitleItem',
full_name='bilibili.community.service.dm.v1.SubtitleItem',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='id', full_name='bilibili.community.service.dm.v1.SubtitleItem.id', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='id_str', full_name='bilibili.community.service.dm.v1.SubtitleItem.id_str', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='lan', full_name='bilibili.community.service.dm.v1.SubtitleItem.lan', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='lan_doc', full_name='bilibili.community.service.dm.v1.SubtitleItem.lan_doc', index=3,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='subtitle_url', full_name='bilibili.community.service.dm.v1.SubtitleItem.subtitle_url', index=4,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='author', full_name='bilibili.community.service.dm.v1.SubtitleItem.author', index=5,
number=6, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=2491,
serialized_end=2645,
)
_USERINFO = _descriptor.Descriptor(
name='UserInfo',
full_name='bilibili.community.service.dm.v1.UserInfo',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='mid', full_name='bilibili.community.service.dm.v1.UserInfo.mid', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='name', full_name='bilibili.community.service.dm.v1.UserInfo.name', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='sex', full_name='bilibili.community.service.dm.v1.UserInfo.sex', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='face', full_name='bilibili.community.service.dm.v1.UserInfo.face', index=3,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='sign', full_name='bilibili.community.service.dm.v1.UserInfo.sign', index=4,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='rank', full_name='bilibili.community.service.dm.v1.UserInfo.rank', index=5,
number=6, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=2647,
serialized_end=2739,
)
_DANMAKUELEM = _descriptor.Descriptor(
name='DanmakuElem',
full_name='bilibili.community.service.dm.v1.DanmakuElem',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='id', full_name='bilibili.community.service.dm.v1.DanmakuElem.id', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='progress', full_name='bilibili.community.service.dm.v1.DanmakuElem.progress', index=1,
number=2, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='mode', full_name='bilibili.community.service.dm.v1.DanmakuElem.mode', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='fontsize', full_name='bilibili.community.service.dm.v1.DanmakuElem.fontsize', index=3,
number=4, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='color', full_name='bilibili.community.service.dm.v1.DanmakuElem.color', index=4,
number=5, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='midHash', full_name='bilibili.community.service.dm.v1.DanmakuElem.midHash', index=5,
number=6, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='content', full_name='bilibili.community.service.dm.v1.DanmakuElem.content', index=6,
number=7, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='ctime', full_name='bilibili.community.service.dm.v1.DanmakuElem.ctime', index=7,
number=8, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='weight', full_name='bilibili.community.service.dm.v1.DanmakuElem.weight', index=8,
number=9, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='action', full_name='bilibili.community.service.dm.v1.DanmakuElem.action', index=9,
number=10, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='pool', full_name='bilibili.community.service.dm.v1.DanmakuElem.pool', index=10,
number=11, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='idStr', full_name='bilibili.community.service.dm.v1.DanmakuElem.idStr', index=11,
number=12, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='attr', full_name='bilibili.community.service.dm.v1.DanmakuElem.attr', index=12,
number=13, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=2742,
serialized_end=2956,
)
_DMPLAYERCONFIGREQ = _descriptor.Descriptor(
name='DmPlayerConfigReq',
full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='ts', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.ts', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='switch', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.switch', index=1,
number=2, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='switch_save', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.switch_save', index=2,
number=3, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='use_default_config', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.use_default_config', index=3,
number=4, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='ai_recommended_switch', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.ai_recommended_switch', index=4,
number=5, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='ai_recommended_level', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.ai_recommended_level', index=5,
number=6, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blocktop', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.blocktop', index=6,
number=7, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blockscroll', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.blockscroll', index=7,
number=8, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blockbottom', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.blockbottom', index=8,
number=9, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blockcolorful', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.blockcolorful', index=9,
number=10, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blockrepeat', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.blockrepeat', index=10,
number=11, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='blockspecial', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.blockspecial', index=11,
number=12, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='opacity', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.opacity', index=12,
number=13, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='scalingfactor', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.scalingfactor', index=13,
number=14, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='domain', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.domain', index=14,
number=15, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='speed', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.speed', index=15,
number=16, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='enableblocklist', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.enableblocklist', index=16,
number=17, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='inlinePlayerDanmakuSwitch', full_name='bilibili.community.service.dm.v1.DmPlayerConfigReq.inlinePlayerDanmakuSwitch', index=17,
number=18, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=2959,
serialized_end=4399,
)
_RESPONSE = _descriptor.Descriptor(
name='Response',
full_name='bilibili.community.service.dm.v1.Response',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='code', full_name='bilibili.community.service.dm.v1.Response.code', index=0,
number=1, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='message', full_name='bilibili.community.service.dm.v1.Response.message', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=4401,
serialized_end=4442,
)
_DANMAKUFLAG = _descriptor.Descriptor(
name='DanmakuFlag',
full_name='bilibili.community.service.dm.v1.DanmakuFlag',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='dmid', full_name='bilibili.community.service.dm.v1.DanmakuFlag.dmid', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='flag', full_name='bilibili.community.service.dm.v1.DanmakuFlag.flag', index=1,
number=2, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=4444,
serialized_end=4485,
)
_DANMAKUFLAGCONFIG = _descriptor.Descriptor(
name='DanmakuFlagConfig',
full_name='bilibili.community.service.dm.v1.DanmakuFlagConfig',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='rec_flag', full_name='bilibili.community.service.dm.v1.DanmakuFlagConfig.rec_flag', index=0,
number=1, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='rec_text', full_name='bilibili.community.service.dm.v1.DanmakuFlagConfig.rec_text', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='rec_switch', full_name='bilibili.community.service.dm.v1.DanmakuFlagConfig.rec_switch', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=4487,
serialized_end=4562,
)
_DANMAKUAIFLAG = _descriptor.Descriptor(
name='DanmakuAIFlag',
full_name='bilibili.community.service.dm.v1.DanmakuAIFlag',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='dm_flags', full_name='bilibili.community.service.dm.v1.DanmakuAIFlag.dm_flags', index=0,
number=1, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=4564,
serialized_end=4644,
)
_DANMUPLAYERVIEWCONFIG = _descriptor.Descriptor(
name='DanmuPlayerViewConfig',
full_name='bilibili.community.service.dm.v1.DanmuPlayerViewConfig',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='danmuku_default_player_config', full_name='bilibili.community.service.dm.v1.DanmuPlayerViewConfig.danmuku_default_player_config', index=0,
number=1, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='danmuku_player_config', full_name='bilibili.community.service.dm.v1.DanmuPlayerViewConfig.danmuku_player_config', index=1,
number=2, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='danmuku_player_dynamic_config', full_name='bilibili.community.service.dm.v1.DanmuPlayerViewConfig.danmuku_player_dynamic_config', index=2,
number=3, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=4647,
serialized_end=4952,
)
_DANMUDEFAULTPLAYERCONFIG = _descriptor.Descriptor(
name='DanmuDefaultPlayerConfig',
full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='player_danmaku_use_default_config', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_use_default_config', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_ai_recommended_switch', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_ai_recommended_switch', index=1,
number=4, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_ai_recommended_level', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_ai_recommended_level', index=2,
number=5, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blocktop', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_blocktop', index=3,
number=6, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockscroll', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_blockscroll', index=4,
number=7, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockbottom', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_blockbottom', index=5,
number=8, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockcolorful', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_blockcolorful', index=6,
number=9, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockrepeat', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_blockrepeat', index=7,
number=10, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockspecial', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_blockspecial', index=8,
number=11, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_opacity', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_opacity', index=9,
number=12, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_scalingfactor', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_scalingfactor', index=10,
number=13, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_domain', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_domain', index=11,
number=14, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_speed', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.player_danmaku_speed', index=12,
number=15, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='inline_player_danmaku_switch', full_name='bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig.inline_player_danmaku_switch', index=13,
number=16, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=4955,
serialized_end=5500,
)
_DANMUPLAYERCONFIG = _descriptor.Descriptor(
name='DanmuPlayerConfig',
full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='player_danmaku_switch', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_switch', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_switch_save', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_switch_save', index=1,
number=2, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_use_default_config', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_use_default_config', index=2,
number=3, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_ai_recommended_switch', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_ai_recommended_switch', index=3,
number=4, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_ai_recommended_level', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_ai_recommended_level', index=4,
number=5, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blocktop', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_blocktop', index=5,
number=6, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockscroll', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_blockscroll', index=6,
number=7, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockbottom', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_blockbottom', index=7,
number=8, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockcolorful', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_blockcolorful', index=8,
number=9, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockrepeat', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_blockrepeat', index=9,
number=10, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_blockspecial', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_blockspecial', index=10,
number=11, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_opacity', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_opacity', index=11,
number=12, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_scalingfactor', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_scalingfactor', index=12,
number=13, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_domain', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_domain', index=13,
number=14, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_speed', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_speed', index=14,
number=15, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_enableblocklist', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.player_danmaku_enableblocklist', index=15,
number=16, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='inline_player_danmaku_switch', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.inline_player_danmaku_switch', index=16,
number=17, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='inline_player_danmaku_config', full_name='bilibili.community.service.dm.v1.DanmuPlayerConfig.inline_player_danmaku_config', index=17,
number=18, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=5503,
serialized_end=6186,
)
_DANMUPLAYERDYNAMICCONFIG = _descriptor.Descriptor(
name='DanmuPlayerDynamicConfig',
full_name='bilibili.community.service.dm.v1.DanmuPlayerDynamicConfig',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='progress', full_name='bilibili.community.service.dm.v1.DanmuPlayerDynamicConfig.progress', index=0,
number=1, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='player_danmaku_domain', full_name='bilibili.community.service.dm.v1.DanmuPlayerDynamicConfig.player_danmaku_domain', index=1,
number=2, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6188,
serialized_end=6263,
)
_PLAYERDANMAKUSWITCH = _descriptor.Descriptor(
name='PlayerDanmakuSwitch',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuSwitch',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuSwitch.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='canIgnore', full_name='bilibili.community.service.dm.v1.PlayerDanmakuSwitch.canIgnore', index=1,
number=2, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6265,
serialized_end=6320,
)
_PLAYERDANMAKUSWITCHSAVE = _descriptor.Descriptor(
name='PlayerDanmakuSwitchSave',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuSwitchSave',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuSwitchSave.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6322,
serialized_end=6362,
)
_PLAYERDANMAKUUSEDEFAULTCONFIG = _descriptor.Descriptor(
name='PlayerDanmakuUseDefaultConfig',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuUseDefaultConfig',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuUseDefaultConfig.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6364,
serialized_end=6410,
)
_PLAYERDANMAKUAIRECOMMENDEDSWITCH = _descriptor.Descriptor(
name='PlayerDanmakuAiRecommendedSwitch',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuAiRecommendedSwitch',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuAiRecommendedSwitch.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6412,
serialized_end=6461,
)
_PLAYERDANMAKUAIRECOMMENDEDLEVEL = _descriptor.Descriptor(
name='PlayerDanmakuAiRecommendedLevel',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuAiRecommendedLevel',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuAiRecommendedLevel.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6463,
serialized_end=6511,
)
_PLAYERDANMAKUBLOCKTOP = _descriptor.Descriptor(
name='PlayerDanmakuBlocktop',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlocktop',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlocktop.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6513,
serialized_end=6551,
)
_PLAYERDANMAKUBLOCKSCROLL = _descriptor.Descriptor(
name='PlayerDanmakuBlockscroll',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockscroll',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockscroll.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6553,
serialized_end=6594,
)
_PLAYERDANMAKUBLOCKBOTTOM = _descriptor.Descriptor(
name='PlayerDanmakuBlockbottom',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockbottom',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockbottom.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6596,
serialized_end=6637,
)
_PLAYERDANMAKUBLOCKCOLORFUL = _descriptor.Descriptor(
name='PlayerDanmakuBlockcolorful',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockcolorful',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockcolorful.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6639,
serialized_end=6682,
)
_PLAYERDANMAKUBLOCKREPEAT = _descriptor.Descriptor(
name='PlayerDanmakuBlockrepeat',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockrepeat',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockrepeat.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6684,
serialized_end=6725,
)
_PLAYERDANMAKUBLOCKSPECIAL = _descriptor.Descriptor(
name='PlayerDanmakuBlockspecial',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockspecial',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuBlockspecial.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6727,
serialized_end=6769,
)
_PLAYERDANMAKUOPACITY = _descriptor.Descriptor(
name='PlayerDanmakuOpacity',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuOpacity',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuOpacity.value', index=0,
number=1, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6771,
serialized_end=6808,
)
_PLAYERDANMAKUSCALINGFACTOR = _descriptor.Descriptor(
name='PlayerDanmakuScalingfactor',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuScalingfactor',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuScalingfactor.value', index=0,
number=1, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6810,
serialized_end=6853,
)
_PLAYERDANMAKUDOMAIN = _descriptor.Descriptor(
name='PlayerDanmakuDomain',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuDomain',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuDomain.value', index=0,
number=1, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6855,
serialized_end=6891,
)
_PLAYERDANMAKUSPEED = _descriptor.Descriptor(
name='PlayerDanmakuSpeed',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuSpeed',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuSpeed.value', index=0,
number=1, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6893,
serialized_end=6928,
)
_PLAYERDANMAKUENABLEBLOCKLIST = _descriptor.Descriptor(
name='PlayerDanmakuEnableblocklist',
full_name='bilibili.community.service.dm.v1.PlayerDanmakuEnableblocklist',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.PlayerDanmakuEnableblocklist.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6930,
serialized_end=6975,
)
_INLINEPLAYERDANMAKUSWITCH = _descriptor.Descriptor(
name='InlinePlayerDanmakuSwitch',
full_name='bilibili.community.service.dm.v1.InlinePlayerDanmakuSwitch',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='bilibili.community.service.dm.v1.InlinePlayerDanmakuSwitch.value', index=0,
number=1, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=6977,
serialized_end=7019,
)
_DMSEGSDKREPLY.fields_by_name['elems'].message_type = _DANMAKUELEM
_DMSEGOTTREPLY.fields_by_name['elems'].message_type = _DANMAKUELEM
_DMSEGMOBILEREPLY.fields_by_name['elems'].message_type = _DANMAKUELEM
_DMSEGMOBILEREPLY.fields_by_name['ai_flag'].message_type = _DANMAKUAIFLAG
_DMVIEWREPLY.fields_by_name['mask'].message_type = _VIDEOMASK
_DMVIEWREPLY.fields_by_name['subtitle'].message_type = _VIDEOSUBTITLE
_DMVIEWREPLY.fields_by_name['ai_flag'].message_type = _DANMAKUFLAGCONFIG
_DMVIEWREPLY.fields_by_name['player_config'].message_type = _DANMUPLAYERVIEWCONFIG
_DMWEBVIEWREPLY.fields_by_name['dm_sge'].message_type = _DMSEGCONFIG
_DMWEBVIEWREPLY.fields_by_name['flag'].message_type = _DANMAKUFLAGCONFIG
_DMWEBVIEWREPLY.fields_by_name['commandDms'].message_type = _COMMANDDM
_DMWEBVIEWREPLY.fields_by_name['player_config'].message_type = _DANMUWEBPLAYERCONFIG
_VIDEOSUBTITLE.fields_by_name['subtitles'].message_type = _SUBTITLEITEM
_SUBTITLEITEM.fields_by_name['author'].message_type = _USERINFO
_DMPLAYERCONFIGREQ.fields_by_name['switch'].message_type = _PLAYERDANMAKUSWITCH
_DMPLAYERCONFIGREQ.fields_by_name['switch_save'].message_type = _PLAYERDANMAKUSWITCHSAVE
_DMPLAYERCONFIGREQ.fields_by_name['use_default_config'].message_type = _PLAYERDANMAKUUSEDEFAULTCONFIG
_DMPLAYERCONFIGREQ.fields_by_name['ai_recommended_switch'].message_type = _PLAYERDANMAKUAIRECOMMENDEDSWITCH
_DMPLAYERCONFIGREQ.fields_by_name['ai_recommended_level'].message_type = _PLAYERDANMAKUAIRECOMMENDEDLEVEL
_DMPLAYERCONFIGREQ.fields_by_name['blocktop'].message_type = _PLAYERDANMAKUBLOCKTOP
_DMPLAYERCONFIGREQ.fields_by_name['blockscroll'].message_type = _PLAYERDANMAKUBLOCKSCROLL
_DMPLAYERCONFIGREQ.fields_by_name['blockbottom'].message_type = _PLAYERDANMAKUBLOCKBOTTOM
_DMPLAYERCONFIGREQ.fields_by_name['blockcolorful'].message_type = _PLAYERDANMAKUBLOCKCOLORFUL
_DMPLAYERCONFIGREQ.fields_by_name['blockrepeat'].message_type = _PLAYERDANMAKUBLOCKREPEAT
_DMPLAYERCONFIGREQ.fields_by_name['blockspecial'].message_type = _PLAYERDANMAKUBLOCKSPECIAL
_DMPLAYERCONFIGREQ.fields_by_name['opacity'].message_type = _PLAYERDANMAKUOPACITY
_DMPLAYERCONFIGREQ.fields_by_name['scalingfactor'].message_type = _PLAYERDANMAKUSCALINGFACTOR
_DMPLAYERCONFIGREQ.fields_by_name['domain'].message_type = _PLAYERDANMAKUDOMAIN
_DMPLAYERCONFIGREQ.fields_by_name['speed'].message_type = _PLAYERDANMAKUSPEED
_DMPLAYERCONFIGREQ.fields_by_name['enableblocklist'].message_type = _PLAYERDANMAKUENABLEBLOCKLIST
_DMPLAYERCONFIGREQ.fields_by_name['inlinePlayerDanmakuSwitch'].message_type = _INLINEPLAYERDANMAKUSWITCH
_DANMAKUAIFLAG.fields_by_name['dm_flags'].message_type = _DANMAKUFLAG
_DANMUPLAYERVIEWCONFIG.fields_by_name['danmuku_default_player_config'].message_type = _DANMUDEFAULTPLAYERCONFIG
_DANMUPLAYERVIEWCONFIG.fields_by_name['danmuku_player_config'].message_type = _DANMUPLAYERCONFIG
_DANMUPLAYERVIEWCONFIG.fields_by_name['danmuku_player_dynamic_config'].message_type = _DANMUPLAYERDYNAMICCONFIG
DESCRIPTOR.message_types_by_name['DmSegSDKReq'] = _DMSEGSDKREQ
DESCRIPTOR.message_types_by_name['DmSegSDKReply'] = _DMSEGSDKREPLY
DESCRIPTOR.message_types_by_name['DmSegOttReq'] = _DMSEGOTTREQ
DESCRIPTOR.message_types_by_name['DmSegOttReply'] = _DMSEGOTTREPLY
DESCRIPTOR.message_types_by_name['DmSegMobileReq'] = _DMSEGMOBILEREQ
DESCRIPTOR.message_types_by_name['DmSegMobileReply'] = _DMSEGMOBILEREPLY
DESCRIPTOR.message_types_by_name['DmViewReq'] = _DMVIEWREQ
DESCRIPTOR.message_types_by_name['DmViewReply'] = _DMVIEWREPLY
DESCRIPTOR.message_types_by_name['DmWebViewReply'] = _DMWEBVIEWREPLY
DESCRIPTOR.message_types_by_name['CommandDm'] = _COMMANDDM
DESCRIPTOR.message_types_by_name['DmSegConfig'] = _DMSEGCONFIG
DESCRIPTOR.message_types_by_name['VideoMask'] = _VIDEOMASK
DESCRIPTOR.message_types_by_name['VideoSubtitle'] = _VIDEOSUBTITLE
DESCRIPTOR.message_types_by_name['DanmuWebPlayerConfig'] = _DANMUWEBPLAYERCONFIG
DESCRIPTOR.message_types_by_name['SubtitleItem'] = _SUBTITLEITEM
DESCRIPTOR.message_types_by_name['UserInfo'] = _USERINFO
DESCRIPTOR.message_types_by_name['DanmakuElem'] = _DANMAKUELEM
DESCRIPTOR.message_types_by_name['DmPlayerConfigReq'] = _DMPLAYERCONFIGREQ
DESCRIPTOR.message_types_by_name['Response'] = _RESPONSE
DESCRIPTOR.message_types_by_name['DanmakuFlag'] = _DANMAKUFLAG
DESCRIPTOR.message_types_by_name['DanmakuFlagConfig'] = _DANMAKUFLAGCONFIG
DESCRIPTOR.message_types_by_name['DanmakuAIFlag'] = _DANMAKUAIFLAG
DESCRIPTOR.message_types_by_name['DanmuPlayerViewConfig'] = _DANMUPLAYERVIEWCONFIG
DESCRIPTOR.message_types_by_name['DanmuDefaultPlayerConfig'] = _DANMUDEFAULTPLAYERCONFIG
DESCRIPTOR.message_types_by_name['DanmuPlayerConfig'] = _DANMUPLAYERCONFIG
DESCRIPTOR.message_types_by_name['DanmuPlayerDynamicConfig'] = _DANMUPLAYERDYNAMICCONFIG
DESCRIPTOR.message_types_by_name['PlayerDanmakuSwitch'] = _PLAYERDANMAKUSWITCH
DESCRIPTOR.message_types_by_name['PlayerDanmakuSwitchSave'] = _PLAYERDANMAKUSWITCHSAVE
DESCRIPTOR.message_types_by_name['PlayerDanmakuUseDefaultConfig'] = _PLAYERDANMAKUUSEDEFAULTCONFIG
DESCRIPTOR.message_types_by_name['PlayerDanmakuAiRecommendedSwitch'] = _PLAYERDANMAKUAIRECOMMENDEDSWITCH
DESCRIPTOR.message_types_by_name['PlayerDanmakuAiRecommendedLevel'] = _PLAYERDANMAKUAIRECOMMENDEDLEVEL
DESCRIPTOR.message_types_by_name['PlayerDanmakuBlocktop'] = _PLAYERDANMAKUBLOCKTOP
DESCRIPTOR.message_types_by_name['PlayerDanmakuBlockscroll'] = _PLAYERDANMAKUBLOCKSCROLL
DESCRIPTOR.message_types_by_name['PlayerDanmakuBlockbottom'] = _PLAYERDANMAKUBLOCKBOTTOM
DESCRIPTOR.message_types_by_name['PlayerDanmakuBlockcolorful'] = _PLAYERDANMAKUBLOCKCOLORFUL
DESCRIPTOR.message_types_by_name['PlayerDanmakuBlockrepeat'] = _PLAYERDANMAKUBLOCKREPEAT
DESCRIPTOR.message_types_by_name['PlayerDanmakuBlockspecial'] = _PLAYERDANMAKUBLOCKSPECIAL
DESCRIPTOR.message_types_by_name['PlayerDanmakuOpacity'] = _PLAYERDANMAKUOPACITY
DESCRIPTOR.message_types_by_name['PlayerDanmakuScalingfactor'] = _PLAYERDANMAKUSCALINGFACTOR
DESCRIPTOR.message_types_by_name['PlayerDanmakuDomain'] = _PLAYERDANMAKUDOMAIN
DESCRIPTOR.message_types_by_name['PlayerDanmakuSpeed'] = _PLAYERDANMAKUSPEED
DESCRIPTOR.message_types_by_name['PlayerDanmakuEnableblocklist'] = _PLAYERDANMAKUENABLEBLOCKLIST
DESCRIPTOR.message_types_by_name['InlinePlayerDanmakuSwitch'] = _INLINEPLAYERDANMAKUSWITCH
DESCRIPTOR.enum_types_by_name['DMAttrBit'] = _DMATTRBIT
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
DmSegSDKReq = _reflection.GeneratedProtocolMessageType('DmSegSDKReq', (_message.Message,), {
'DESCRIPTOR' : _DMSEGSDKREQ,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmSegSDKReq)
})
_sym_db.RegisterMessage(DmSegSDKReq)
DmSegSDKReply = _reflection.GeneratedProtocolMessageType('DmSegSDKReply', (_message.Message,), {
'DESCRIPTOR' : _DMSEGSDKREPLY,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmSegSDKReply)
})
_sym_db.RegisterMessage(DmSegSDKReply)
DmSegOttReq = _reflection.GeneratedProtocolMessageType('DmSegOttReq', (_message.Message,), {
'DESCRIPTOR' : _DMSEGOTTREQ,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmSegOttReq)
})
_sym_db.RegisterMessage(DmSegOttReq)
DmSegOttReply = _reflection.GeneratedProtocolMessageType('DmSegOttReply', (_message.Message,), {
'DESCRIPTOR' : _DMSEGOTTREPLY,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmSegOttReply)
})
_sym_db.RegisterMessage(DmSegOttReply)
DmSegMobileReq = _reflection.GeneratedProtocolMessageType('DmSegMobileReq', (_message.Message,), {
'DESCRIPTOR' : _DMSEGMOBILEREQ,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmSegMobileReq)
})
_sym_db.RegisterMessage(DmSegMobileReq)
DmSegMobileReply = _reflection.GeneratedProtocolMessageType('DmSegMobileReply', (_message.Message,), {
'DESCRIPTOR' : _DMSEGMOBILEREPLY,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmSegMobileReply)
})
_sym_db.RegisterMessage(DmSegMobileReply)
DmViewReq = _reflection.GeneratedProtocolMessageType('DmViewReq', (_message.Message,), {
'DESCRIPTOR' : _DMVIEWREQ,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmViewReq)
})
_sym_db.RegisterMessage(DmViewReq)
DmViewReply = _reflection.GeneratedProtocolMessageType('DmViewReply', (_message.Message,), {
'DESCRIPTOR' : _DMVIEWREPLY,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmViewReply)
})
_sym_db.RegisterMessage(DmViewReply)
DmWebViewReply = _reflection.GeneratedProtocolMessageType('DmWebViewReply', (_message.Message,), {
'DESCRIPTOR' : _DMWEBVIEWREPLY,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmWebViewReply)
})
_sym_db.RegisterMessage(DmWebViewReply)
CommandDm = _reflection.GeneratedProtocolMessageType('CommandDm', (_message.Message,), {
'DESCRIPTOR' : _COMMANDDM,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.CommandDm)
})
_sym_db.RegisterMessage(CommandDm)
DmSegConfig = _reflection.GeneratedProtocolMessageType('DmSegConfig', (_message.Message,), {
'DESCRIPTOR' : _DMSEGCONFIG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmSegConfig)
})
_sym_db.RegisterMessage(DmSegConfig)
VideoMask = _reflection.GeneratedProtocolMessageType('VideoMask', (_message.Message,), {
'DESCRIPTOR' : _VIDEOMASK,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.VideoMask)
})
_sym_db.RegisterMessage(VideoMask)
VideoSubtitle = _reflection.GeneratedProtocolMessageType('VideoSubtitle', (_message.Message,), {
'DESCRIPTOR' : _VIDEOSUBTITLE,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.VideoSubtitle)
})
_sym_db.RegisterMessage(VideoSubtitle)
DanmuWebPlayerConfig = _reflection.GeneratedProtocolMessageType('DanmuWebPlayerConfig', (_message.Message,), {
'DESCRIPTOR' : _DANMUWEBPLAYERCONFIG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DanmuWebPlayerConfig)
})
_sym_db.RegisterMessage(DanmuWebPlayerConfig)
SubtitleItem = _reflection.GeneratedProtocolMessageType('SubtitleItem', (_message.Message,), {
'DESCRIPTOR' : _SUBTITLEITEM,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.SubtitleItem)
})
_sym_db.RegisterMessage(SubtitleItem)
UserInfo = _reflection.GeneratedProtocolMessageType('UserInfo', (_message.Message,), {
'DESCRIPTOR' : _USERINFO,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.UserInfo)
})
_sym_db.RegisterMessage(UserInfo)
DanmakuElem = _reflection.GeneratedProtocolMessageType('DanmakuElem', (_message.Message,), {
'DESCRIPTOR' : _DANMAKUELEM,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DanmakuElem)
})
_sym_db.RegisterMessage(DanmakuElem)
DmPlayerConfigReq = _reflection.GeneratedProtocolMessageType('DmPlayerConfigReq', (_message.Message,), {
'DESCRIPTOR' : _DMPLAYERCONFIGREQ,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DmPlayerConfigReq)
})
_sym_db.RegisterMessage(DmPlayerConfigReq)
Response = _reflection.GeneratedProtocolMessageType('Response', (_message.Message,), {
'DESCRIPTOR' : _RESPONSE,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.Response)
})
_sym_db.RegisterMessage(Response)
DanmakuFlag = _reflection.GeneratedProtocolMessageType('DanmakuFlag', (_message.Message,), {
'DESCRIPTOR' : _DANMAKUFLAG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DanmakuFlag)
})
_sym_db.RegisterMessage(DanmakuFlag)
DanmakuFlagConfig = _reflection.GeneratedProtocolMessageType('DanmakuFlagConfig', (_message.Message,), {
'DESCRIPTOR' : _DANMAKUFLAGCONFIG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DanmakuFlagConfig)
})
_sym_db.RegisterMessage(DanmakuFlagConfig)
DanmakuAIFlag = _reflection.GeneratedProtocolMessageType('DanmakuAIFlag', (_message.Message,), {
'DESCRIPTOR' : _DANMAKUAIFLAG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DanmakuAIFlag)
})
_sym_db.RegisterMessage(DanmakuAIFlag)
DanmuPlayerViewConfig = _reflection.GeneratedProtocolMessageType('DanmuPlayerViewConfig', (_message.Message,), {
'DESCRIPTOR' : _DANMUPLAYERVIEWCONFIG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DanmuPlayerViewConfig)
})
_sym_db.RegisterMessage(DanmuPlayerViewConfig)
DanmuDefaultPlayerConfig = _reflection.GeneratedProtocolMessageType('DanmuDefaultPlayerConfig', (_message.Message,), {
'DESCRIPTOR' : _DANMUDEFAULTPLAYERCONFIG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DanmuDefaultPlayerConfig)
})
_sym_db.RegisterMessage(DanmuDefaultPlayerConfig)
DanmuPlayerConfig = _reflection.GeneratedProtocolMessageType('DanmuPlayerConfig', (_message.Message,), {
'DESCRIPTOR' : _DANMUPLAYERCONFIG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DanmuPlayerConfig)
})
_sym_db.RegisterMessage(DanmuPlayerConfig)
DanmuPlayerDynamicConfig = _reflection.GeneratedProtocolMessageType('DanmuPlayerDynamicConfig', (_message.Message,), {
'DESCRIPTOR' : _DANMUPLAYERDYNAMICCONFIG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.DanmuPlayerDynamicConfig)
})
_sym_db.RegisterMessage(DanmuPlayerDynamicConfig)
PlayerDanmakuSwitch = _reflection.GeneratedProtocolMessageType('PlayerDanmakuSwitch', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUSWITCH,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuSwitch)
})
_sym_db.RegisterMessage(PlayerDanmakuSwitch)
PlayerDanmakuSwitchSave = _reflection.GeneratedProtocolMessageType('PlayerDanmakuSwitchSave', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUSWITCHSAVE,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuSwitchSave)
})
_sym_db.RegisterMessage(PlayerDanmakuSwitchSave)
PlayerDanmakuUseDefaultConfig = _reflection.GeneratedProtocolMessageType('PlayerDanmakuUseDefaultConfig', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUUSEDEFAULTCONFIG,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuUseDefaultConfig)
})
_sym_db.RegisterMessage(PlayerDanmakuUseDefaultConfig)
PlayerDanmakuAiRecommendedSwitch = _reflection.GeneratedProtocolMessageType('PlayerDanmakuAiRecommendedSwitch', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUAIRECOMMENDEDSWITCH,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuAiRecommendedSwitch)
})
_sym_db.RegisterMessage(PlayerDanmakuAiRecommendedSwitch)
PlayerDanmakuAiRecommendedLevel = _reflection.GeneratedProtocolMessageType('PlayerDanmakuAiRecommendedLevel', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUAIRECOMMENDEDLEVEL,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuAiRecommendedLevel)
})
_sym_db.RegisterMessage(PlayerDanmakuAiRecommendedLevel)
PlayerDanmakuBlocktop = _reflection.GeneratedProtocolMessageType('PlayerDanmakuBlocktop', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUBLOCKTOP,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuBlocktop)
})
_sym_db.RegisterMessage(PlayerDanmakuBlocktop)
PlayerDanmakuBlockscroll = _reflection.GeneratedProtocolMessageType('PlayerDanmakuBlockscroll', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUBLOCKSCROLL,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuBlockscroll)
})
_sym_db.RegisterMessage(PlayerDanmakuBlockscroll)
PlayerDanmakuBlockbottom = _reflection.GeneratedProtocolMessageType('PlayerDanmakuBlockbottom', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUBLOCKBOTTOM,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuBlockbottom)
})
_sym_db.RegisterMessage(PlayerDanmakuBlockbottom)
PlayerDanmakuBlockcolorful = _reflection.GeneratedProtocolMessageType('PlayerDanmakuBlockcolorful', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUBLOCKCOLORFUL,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuBlockcolorful)
})
_sym_db.RegisterMessage(PlayerDanmakuBlockcolorful)
PlayerDanmakuBlockrepeat = _reflection.GeneratedProtocolMessageType('PlayerDanmakuBlockrepeat', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUBLOCKREPEAT,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuBlockrepeat)
})
_sym_db.RegisterMessage(PlayerDanmakuBlockrepeat)
PlayerDanmakuBlockspecial = _reflection.GeneratedProtocolMessageType('PlayerDanmakuBlockspecial', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUBLOCKSPECIAL,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuBlockspecial)
})
_sym_db.RegisterMessage(PlayerDanmakuBlockspecial)
PlayerDanmakuOpacity = _reflection.GeneratedProtocolMessageType('PlayerDanmakuOpacity', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUOPACITY,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuOpacity)
})
_sym_db.RegisterMessage(PlayerDanmakuOpacity)
PlayerDanmakuScalingfactor = _reflection.GeneratedProtocolMessageType('PlayerDanmakuScalingfactor', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUSCALINGFACTOR,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuScalingfactor)
})
_sym_db.RegisterMessage(PlayerDanmakuScalingfactor)
PlayerDanmakuDomain = _reflection.GeneratedProtocolMessageType('PlayerDanmakuDomain', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUDOMAIN,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuDomain)
})
_sym_db.RegisterMessage(PlayerDanmakuDomain)
PlayerDanmakuSpeed = _reflection.GeneratedProtocolMessageType('PlayerDanmakuSpeed', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUSPEED,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuSpeed)
})
_sym_db.RegisterMessage(PlayerDanmakuSpeed)
PlayerDanmakuEnableblocklist = _reflection.GeneratedProtocolMessageType('PlayerDanmakuEnableblocklist', (_message.Message,), {
'DESCRIPTOR' : _PLAYERDANMAKUENABLEBLOCKLIST,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.PlayerDanmakuEnableblocklist)
})
_sym_db.RegisterMessage(PlayerDanmakuEnableblocklist)
InlinePlayerDanmakuSwitch = _reflection.GeneratedProtocolMessageType('InlinePlayerDanmakuSwitch', (_message.Message,), {
'DESCRIPTOR' : _INLINEPLAYERDANMAKUSWITCH,
'__module__' : 'dm_pb2'
# @@protoc_insertion_point(class_scope:bilibili.community.service.dm.v1.InlinePlayerDanmakuSwitch)
})
_sym_db.RegisterMessage(InlinePlayerDanmakuSwitch)
_DM = _descriptor.ServiceDescriptor(
name='DM',
full_name='bilibili.community.service.dm.v1.DM',
file=DESCRIPTOR,
index=0,
serialized_options=None,
serialized_start=7100,
serialized_end=7654,
methods=[
_descriptor.MethodDescriptor(
name='DmSegMobile',
full_name='bilibili.community.service.dm.v1.DM.DmSegMobile',
index=0,
containing_service=None,
input_type=_DMSEGMOBILEREQ,
output_type=_DMSEGMOBILEREPLY,
serialized_options=None,
),
_descriptor.MethodDescriptor(
name='DmView',
full_name='bilibili.community.service.dm.v1.DM.DmView',
index=1,
containing_service=None,
input_type=_DMVIEWREQ,
output_type=_DMVIEWREPLY,
serialized_options=None,
),
_descriptor.MethodDescriptor(
name='DmPlayerConfig',
full_name='bilibili.community.service.dm.v1.DM.DmPlayerConfig',
index=2,
containing_service=None,
input_type=_DMPLAYERCONFIGREQ,
output_type=_RESPONSE,
serialized_options=None,
),
_descriptor.MethodDescriptor(
name='DmSegOtt',
full_name='bilibili.community.service.dm.v1.DM.DmSegOtt',
index=3,
containing_service=None,
input_type=_DMSEGOTTREQ,
output_type=_DMSEGOTTREPLY,
serialized_options=None,
),
_descriptor.MethodDescriptor(
name='DmSegSDK',
full_name='bilibili.community.service.dm.v1.DM.DmSegSDK',
index=4,
containing_service=None,
input_type=_DMSEGSDKREQ,
output_type=_DMSEGSDKREPLY,
serialized_options=None,
),
])
_sym_db.RegisterServiceDescriptor(_DM)
DESCRIPTOR.services_by_name['DM'] = _DM
# @@protoc_insertion_point(module_scope)
| python |
print("Ausgangsabundanz der Bakterienpopulation 100 Exemplare")
print("Verdopplung alle 30 min")
abundanz=100
stunde=0
while stunde<=48:
stunde+=1
abundanz=abundanz*4
print("Stunde",stunde,abundanz,"Ind.")
abundanz1=100
for zeit in range(49):
print("Stunde",zeit,"",abundanz1,"Ind.")
abundanz1*=4
| python |
"""
Zip() -> cria um iterável (zip object), formando pares com cada elemento do 2 iteráveis passados
"""
l1 = [1, 2, 3]
l2 = [4, 5, 6]
zip1 = zip(l1, l2)
print(type(zip1))
print(zip1)
# print(list(zip1))
"""
OBS.: Some da memória após o primeiro uso
Se estiver com iteráveis de tamanhos diferentes, ele considera o menor tamanho
"""
for t in zip1:
print(list(t))
| python |
from flask import Flask, render_template, request, Response, redirect, url_for
from flask_socketio import SocketIO, emit
from crazyivan import CrazyIvan
import utils
import datetime
import logging
from functools import wraps
import time
utils.init_logger()
async_mode = None
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, async_mode=async_mode, logger=False, engineio_logger=False)
thread = None
stopped = True
profit = 0
def check_auth(username, password):
"""This function is called to check if a username /
password combination is valid.
"""
return username == 'admin' and password == 'admin'
def authenticate():
"""Sends a 401 response that enables basic auth"""
return Response(
'ACCESS DENIED. \n'
'Go away!', 401,
{'WWW-Authenticate': 'Basic realm="Login to Crazy Ivan"'})
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated
@app.route('/', defaults={'pair': 'btcusd'})
@app.route('/<pair>')
@requires_auth
def index(pair='btcusd'):
global profit
if pair not in ['btcusd', 'ltcusd', 'ethusd']:
return Response('Crazy Ivan denied this currency. \n', 404)
return render_template('index.html',
name='Crazy Ivan v0.8b',
stopped=int(stopped),
profit=profit,
pair=pair)
def log_event(name, data, pair_name="all"):
logging.info("{name} - {data}".format(name=pair_name, data=data))
global profit
if name == "profit":
profit = data
socketio.emit('my_response',
{'pair': pair_name,
'data': data,
'name': name,
'date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")},
namespace='/test')
ivans = {'btcusd': None, 'ltcusd': None} # 'ethusd': None,
for ivan in ivans:
config_name = 'config-{pair}.json'.format(pair=ivan)
config = utils.load_config(config_name)
ivans[ivan] = CrazyIvan(log_event, config, ivan)
def background_thread():
while True:
try:
global stopped
if not stopped:
is_new_minute = datetime.datetime.now().second < 2
for i in ivans:
ivans[i].update(is_new_minute)
except Exception as e:
log_event("error", e)
socketio.sleep(2)
@socketio.on('my_event', namespace='/test')
def test_message(message):
emit('my_response',
{'data': str(message)})
@socketio.on('my_ping', namespace='/test')
def ping_pong():
emit('my_pong')
@socketio.on('connect', namespace='/test')
def test_connect():
log_event('info', 'Connected to Crazy Ivan. Bot is <strong>{state}</strong>.'.format(state='Active' if not stopped else 'Inactive'))
emit('stopped', stopped, namespace='/test')
@socketio.on('save_config', namespace='/test')
def save_settings(data):
pair = data['pair']
config = data['data']
config_name = 'config-{pair}.json'.format(pair=pair)
utils.save_config(config, file_name=config_name)
ivans[pair].update_config(config)
log_event('info', 'Setting {pair} saved.'.format(pair=pair))
@socketio.on('load_config_req', namespace='/test')
def load_settings(pair):
config_name = 'config-{pair}.json'.format(pair=pair)
config = utils.load_config(config_name)
emit('load_config_res', {'data': config, 'pair': pair}, namespace='/test')
@socketio.on('restart', namespace='/test')
def restart():
log_event('info', 'Restart... Not implemented.')
@socketio.on('start', namespace='/test')
def start(state):
global stopped
stopped = state
log_event('action', 'Bot is activated.' if not state else 'Bot is deactivated.')
if thread is None:
thread = socketio.start_background_task(target=background_thread)
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=5000, debug=True)
| python |
from enum import IntEnum
from .exceptions import *
from .board import Board, Item, CellState
from .difficulties import Difficulty, DifficultyConfig
class PlayState(IntEnum):
INITIAL_STATE = 0
MAKE_MOVE = 1
FAILED = 2
VICTORY = 3
class ThrillDigger:
__board = None
__price = 0
__score = 0
__dug_up = 0
__state = PlayState.INITIAL_STATE
def __init__(self, difficulty: Difficulty, width = 0, height = 0, bombs = 0, rupoors = 0, price = 0):
config = DifficultyConfig[difficulty]
if difficulty == Difficulty.CUSTOM:
config["width"] = width
config["height"] = height
config["bombs"] = bombs
config["rupoors"] = rupoors
config["price"] = price
self.__price = config["price"]
self.__board = Board(config["width"], config["height"], config["bombs"], config["rupoors"])
def reset(self):
self.__state = PlayState.INITIAL_STATE
width, height = self.__board.get_shape()
bombs, rupoors = self.__board.get_hazards()
self.__score = 0
self.__dug_up = 0
self.__board = Board(width, height, bombs, rupoors)
def play(self):
if (self.__state != PlayState.INITIAL_STATE):
raise GameAlreadyStartedError("Some holes have been previously dug up")
self.execute_play_strategy()
if self.__state == PlayState.VICTORY:
return True
elif self.__state == PlayState.FAILED:
return False
else:
raise UnfinishedGameError("Strategy finished without winning or losing")
def dig(self,x,y):
if (self.__state == PlayState.VICTORY or self.__state == PlayState.FAILED):
raise GameIsOverError("Game already finished")
previous_state = self.__board.cell_state(x,y)
item = self.__board.dig(x,y)
# Dug up only increases if we dig up treasure and we didn't already dug up that cell
if item != Item.RUPOOR or item != Item.RUPOOR:
if previous_state == CellState.COVERED:
self.__dug_up += 1
if item == Item.BOMB:
self.__state = PlayState.FAILED
else:
# Only increase score if we didn't previously dug up that item
if previous_state == CellState.COVERED:
self.__score = max(0, self.__score + int(item))
self.__state = PlayState.MAKE_MOVE
width, height = self.__board.get_shape()
bombs,rupoors = self.__board.get_hazards()
if ((width*height)-(bombs+rupoors)) == self.__dug_up:
self.__state = PlayState.VICTORY
return item
def get_price(self):
return self.__price
def get_score(self):
return self.__score
def get_play_state(self):
return self.__state
def get_board(self):
return self.__board.get_board()
def get_pretty_board(self):
return str(self.__board)
def get_board_shape(self):
return self.__board.get_shape()
def get_board_hazards(self):
return self.__board.get_hazards()
def execute_play_strategy(self):
pass | python |
import FWCore.ParameterSet.Config as cms
from Configuration.EventContent.EventContent_cff import *
btagDijetEventContent = cms.PSet(
outputCommands = cms.untracked.vstring()
)
AODSIMbtagDijetEventContent = cms.PSet(
outputCommands = cms.untracked.vstring()
)
RECOSIMbtagDijetEventContent = cms.PSet(
outputCommands = cms.untracked.vstring()
)
btagDijetEventSelection = cms.PSet(
SelectEvents = cms.untracked.PSet(
SelectEvents = cms.vstring('btagDijetPath')
)
)
AODSIMbtagDijetEventContent.outputCommands.extend(AODSIMEventContent.outputCommands)
AODSIMbtagDijetEventContent.outputCommands.extend(btagDijetEventContent.outputCommands)
RECOSIMbtagDijetEventContent.outputCommands.extend(RECOSIMEventContent.outputCommands)
RECOSIMbtagDijetEventContent.outputCommands.extend(btagDijetEventContent.outputCommands)
| python |
def reverse_delete(s,c):
"""Task
We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
then check if the result string is palindrome.
A string is called palindrome if it reads the same backward as forward.
You should return a tuple containing the result string and True/False for the check.
Example
For s = "abcde", c = "ae", the result should be ('bcd',False)
For s = "abcdef", c = "b" the result should be ('acdef',False)
For s = "abcdedcba", c = "ab", the result should be ('cdedc',True)
Example solution:
# line 1
ret = ''
# line 2
for char in s:
# line 3
if char in c:
# line 4
ret += char
# line 5
return (ret,ret[::-1] == ret)
"""
# Please print out which line of the above program contains an error. E.g. if the bug is on line 4 then print 4
# END OF CONTEXT
print("3")
# END OF SOLUTION
def check(candidate):
import io
from contextlib import redirect_stdout
f = io.StringIO()
with redirect_stdout(f):
candidate('','')
out = f.getvalue().strip('\n')
assert "3" == out
for i in range(0, 10):
if i != 3:
assert str(i) != out
if __name__ == '__main__':
check(reverse_delete)
| python |
"""Package broker."""
from . import Broker, python3, load_output
from jujuna.exporters import Exporter
import logging
log = logging.getLogger('jujuna.tests.broker')
class Package(Broker):
"""Mount broker."""
def __init__(self):
"""Init broker."""
super().__init__()
async def run(self, test_case, unit, idx):
"""Run tests."""
rows = []
async with Exporter(unit, self.named) as exporter:
try:
act = await unit.run(python3(exporter), timeout=10)
results = load_output(act.data['results'])
except Exception as exc:
log.debug(exc)
results = {'installed': []}
# print(results['installed'].keys())
if 'installed' in test_case:
for condition in test_case['installed']:
rows.append((idx, '{} == {}'.format(condition, 'installed'), condition in results['installed']), )
return rows
| python |
# from ..GenericInstrument import GenericInstrument
from ..IEEE488 import IEEE488
from ..SCPI import SCPI
'''
opts = inst.query('OO').split(',') # Anritsu output options
fmin, fmax = 2e9, 10e9
amin, amax = -30, 21
if '5' in opts:
fmin = 10e6
if '2A' in opts:
amin = -110
print(amin, amax, fmin, fmax)
testvalue = 24.01
if amin <= testvalue <= amax:
print(True)
'''
class amplitudelimiter(object):
"""Class to limit upper amplitude value applied to a SignalGenerator.
Applied by decorator @amplitudelimiter
"""
def __init__(self, f, *args, **kwargs):
"""If there are no decorator arguments, the function to be decorated is passed to the constructor."""
# print(f)
# print(*args)
# print(**kwargs)
# print("Inside __init__()")
self.f = f
def __call__(self, f, *args, **kwargs):
"""The __call__ method is not called until the decorated function is called."""
# print(f)
# print(*args)
# print(**kwargs)
# print("Inside __call__()")
setpoint = float(*args)
if setpoint > f._amplitudelimit:
print(f"Amplimit ({f._amplitudelimit}) reached with setpoint ({setpoint}) on {f.inst}")
else:
self.f(f, *args)
# print("After self.f(*args)")
class AnritsuMG369nAB(IEEE488):
"""."""
def __init__(self, inst):
super().__init__(inst)
self.inst.read_termination = '\r\n'
self.inst.write_termination = '\n'
self._fmin, self._fmax = float(self.query('OFL')) * 1e6, float(self.query('OFH')) * 1e6 # Min, Max Frequency
self._options = [str(i) for i in self.query('OO').split(',')] # Options installed
self._preset_()
self._amplitudelimit = 0
def _preset_(self):
self.write('CF0') # select F0
self.write('L0') # select L0
self.write('LOG') # operate in dBm / LIN in mV
self.output = False
self.write('RO1') # RF state at reset to off
self.frequencymultiplier = 1
self.leveloffset = 0
self.write('LO0') # Level offset off
self.write('RL')
@property
def frequency(self): # Responce is in MHz
return round(float(self.query('OF0')) * 1e6, 2)
@frequency.setter
def frequency(self, frequency):
self.write(f'F0{frequency:.2f}HZ')
@property
def frequencymultiplier(self):
return float(self.query('OFM')) # Output Frequency Multiplier
@frequencymultiplier.setter
def frequencymultiplier(self, multiplier=1):
self.write(f"FRS{multiplier}TMS") # Set Frequency Multiplier
@property
def amplitude(self):
return float(self.query('OL0')) # Output Level 0
@amplitude.setter
@amplitudelimiter
def amplitude(self, amplitude):
self.write(f'L0{amplitude:.2f}DM')
@property
def output(self):
return NotImplemented
@output.setter
def output(self, boolean=False):
self.write(f'RF{boolean:d}')
@property
def leveloffset(self):
return float(self.query('OLO'))
@leveloffset.setter
def leveloffset(self, leveloffset):
self.write(f'LOS{leveloffset:.2f}DB')
'''
# 'F5 100 MZ ACW' # Activate CW on open frequency param
# AT0 # deselect coupling of ALC attenuator
# AT1 # select coupling of ALC attenuator
# ATT00 to ATT11 nn * 10 dB.
# CS0 # Turns off CW Ramp
# LVP # set output -1dB of Peak power shy of
# gen.query('OI')
# gen.query('OVN') # ROM Version
# PS0 # Phase Offset Off
# PSO{phase}DG
# PU{n}
# 0 dBm
# 1 mV
# 2 dBmV
# TR0 , TR1 # when step attenuator is installed use 0 or 40dB of attenuation ~source match termination
# Need to preset : amp offset, freq offset, used freq, used amp, used mod, used pulse
LOS Opens the level offset
parameter.
+100dB to 100dB
(logarithmic); +xxx mV to
xxx mV (linear)
DB (log)
VT (linear
# XL0
Opens the L0 parameter. Power level range of the
MG369XB model
DM (log)
VT (linear)
'''
'''
class AnritsuMG369nx(SignalGenerator, IEEE488):
"""ANRITSU,MG369nx."""
def __repr__(self):
"""."""
return(f"{__class__}, {self.instrument}")
def __init__(self, instrument):
"""."""
super().__init__(instrument)
# self.log.info('Creating an instance of\t' + str(__class__))
self.log.info(f'Creating {str(__class__.__name__)} for {self.instrument}')
# self.options = self.query("*OPT?").strip().split(',')
# self.amps = [-110, 30]
self.freqs = [2e9, 10e9]
# self.write("*CLS") # clear error status
# self.write("*CLS") # clear error status
# self.write('CF0') # Set CW mode at F0, Opens F0 parameter.
# self.write('CM0') # Set CW mode at M0, Opens M0 parameter.
# AL0
# self.write('LOG')
# self.query('SAF') # Outputs the current instrument setup to the controller.
# RCF Readies the MG369XB to receive a new instrument setup recalled from the controller
self.query('OO') # Returns the instrument option string to the controller
self.write('RO1') # Selects RF to be off at reset
self.write('RL1') # Release to Local
@property
def frequency(self):
"""."""
return(float(self.query("OF0").strip()) * 1e6) # Responce is in MHz
@frequency.setter
def frequency(self, frequency):
self.write(f"F0{frequency:.0f} HZ")
@property
def amplitude(self):
"""."""
return(self.query("OL0")) # OLO
@amplitude.setter
@amplitudelimiter
def amplitude(self, amplitude):
self.write(f"L0{amplitude:.2f}DM")
@property
def output(self):
"""."""
return NotImplemented
#ORF
@output.setter
def output(self, boolean=False):
self.write(f"RF{boolean:d}")
class AnritsuMG3691B(AnritsuMG369nx): # ANRITSU,MG3691B,
"""Antitsu MG3691B 2e9, 10e9.
.. figure:: images/SignalGenerator/AnritsuMG3691B.jpg
"""
# Need to preset : amp offset, freq offset, used freq, used amp, used mod, used pulse
def __repr__(self):
"""."""
return(f"{__class__}, {self.instrument}")
def __init__(self, instrument):
"""."""
super().__init__(instrument)
# self.log.info('Creating an instance of\t' + str(__class__))
self.log.info(f'Creating {str(__class__.__name__)} for {self.instrument}')
assert self.IDN.startswith('ANRITSU,MG3691B,')
self.amps = [-110, 30]
self.freqs = [10e6, 10e9]
class AnritsuMG3692A(AnritsuMG369nx): # ANRITSU,MG3692A,
"""Antitsu MG3692A 2e9, 20e9.
.. figure:: images/SignalGenerator/AnritsuMG3692A.jpg
"""
# Need to preset : amp offset, freq offset, used freq, used amp, used mod, used pulse
def __repr__(self):
"""."""
return(f"{__class__}, {self.instrument}")
def __init__(self, instrument):
"""."""
super().__init__(instrument)
# self.log.info('Creating an instance of\t' + str(__class__))
self.log.info(f'Creating {str(__class__.__name__)} for {self.instrument}')
assert self.IDN.startswith('ANRITSU,MG3692A,')
self.amps = [-110, 30]
self.freqs = [10e6, 20e9]
class AnritsuMG3693A(AnritsuMG369nx): # ANRITSU,MG3693A,
"""Antitsu MG3693A 2e9, 30e9.
.. figure:: images/SignalGenerator/AnritsuMG3693A.jpg
"""
# Need to preset : amp offset, freq offset, used freq, used amp, used mod, used pulse
def __repr__(self):
"""."""
return(f"{__class__}, {self.instrument}")
def __init__(self, instrument):
"""."""
super().__init__(instrument)
# self.log.info('Creating an instance of\t' + str(__class__))
self.log.info(f'Creating {str(__class__.__name__)} for {self.instrument}')
assert self.IDN.startswith('ANRITSU,MG3693A,')
self.amps = [-110, 30]
self.freqs = [2e9, 30e9]
class AnritsuMG3695B(AnritsuMG369nx): # ANRITSU,MG3695B,
"""Antitsu MG3695A 2e9, 50e9.
.. figure:: images/SignalGenerator/AnritsuMG3695A.jpg
"""
# Need to preset : amp offset, freq offset, used freq, used amp, used mod, used pulse
def __repr__(self):
"""."""
return(f"{__class__}, {self.instrument}")
def __init__(self, instrument):
"""."""
super().__init__(instrument)
# self.log.info('Creating an instance of\t' + str(__class__))
self.log.info(f'Creating {str(__class__.__name__)} for {self.instrument}')
# assert self.IDN.startswith('ANRITSU,MG3693A,')
self.amps = [-110, 20]
self.freqs = [8e6, 50e9]
'''
| python |
from gensim.models import Word2Vec
def word_embedding(corpus):
"""Construct the word embedding model for a given corpus.
:param corpus: List of sentences.
:returns: Word2Vec model.
"""
sentences = [[x for x in t.split()] for t in corpus]
return Word2Vec(sentences, min_count = 1)
if __name__ == '__main__':
sample_corpus = [
"data science",
"jeury data science analytic",
"machine learning",
"deep learning"
]
model = word_embedding(sample_corpus)
print(model)
print(model.similarity('data', 'science'))
print(model['learning'])
| python |
# Problem: https://www.hackerrank.com/challenges/itertools-product/problem
# Score: 10
| python |
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: Jeremy Parks
# Note: Requires Python 3.3.x or higher
desc = "gems"
# Base type : settings pair
items = {
"01 Quality Gem 20": {"class": "Gems", "other": ["Quality >= 20"], "type": "currency normal"},
"02 Quality Gem High": {"class": "Gems", "other": ["Quality >= 10"], "type": "gem normal"},
"03 Quality Gem": {"class": "Gems", "other": ["Quality >= 1"], "type": "ignore"},
"04 Leveled Gem ": {"class": "Gems", "other": ["GemLevel >= 2"], "type": "gem low"},
"1 Portal": {"baseexact": "Portal", "class": "Gems", "type": "gem normal"},
"0 Awakened Gems": {"base": 'Awakened', "class": "Gems", "type": "gem high"},
"7 Vaal Gems": {"base": "Vaal", "class": "Gems", "type": "gem low"},
"8 Other Gems Leveling": {"class": "Gems", "other": ["AreaLevel < 68"], "type": "gem low"},
} | python |
N = int(input())
S = list(str(N))
S_num_sum = sum(list(map(int, S)))
if N % S_num_sum == 0:
print("Yes")
else:
print("No")
| python |
from os import name
from service.database.models import Notice
from requests import post
"""
TG 消息推送
"""
def post_tg(config,admin_account,data):
#默认为文本消息
TG_TOKEN = config['TG_TOKEN']
CHAT_ID = admin_account
telegram_message = f"管理员您好:{data['contact']}购买的{data['name']}卡密发送成功!"
params = (
('chat_id', CHAT_ID),
('text', telegram_message),
('parse_mode', "Markdown"), #可选Html或Markdown
('disable_web_page_preview', "yes")
)
telegram_url = "https://api.telegram.org/bot" + TG_TOKEN + "/sendMessage"
try:
telegram_req = post(telegram_url, params=params)
telegram_status = telegram_req.status_code
if telegram_status == 200:
# print(f"INFO: Telegram Message sent")
return True
except:
pass
return False
if __name__ == "__main__":
post_tg('你好,佰阅!')
# t.me/kamiFaka_bot 公共频道 | python |
# Generated by Django 3.2.13 on 2022-05-26 13:39
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("core", "0007_auto_20220404_1519"),
]
operations = [
migrations.CreateModel(
name="NewsletterSubscription",
fields=[
(
"id",
models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("created_date", models.DateTimeField(auto_now_add=True)),
("modified_date", models.DateTimeField(auto_now=True)),
("is_active", models.BooleanField(default=False)),
("email_address", models.CharField(max_length=256)),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="newsletter_signups",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"abstract": False,
},
),
]
| python |
"""Route to all common guilds between the bot and the user"""
import requests
import json
from databases.token import Token
from helpers.crypt import hash_str
import constants
API_ENDPOINT = 'https://discordapp.com/api/v6'
def get(handler, parameters, url_parameters, ids_parameters):
"""GET method"""
token = handler.session.query(Token).where(Token.session_token == hash_str(handler.session_token)).first()
if not token:
handler.logger.debug("Unauthorized")
handler.send_error(401, "Unauthorized.")
return
headers = {
'Authorization': 'Bearer ' + token.access_token
}
try:
r = requests.get(API_ENDPOINT + '/users/@me/guilds', headers=headers)
r.raise_for_status()
except requests.exceptions.HTTPError:
handler.logger.exception("Couldn't get the data from Discord API.")
handler.logger.debug(r.text)
handler.send_error(500, "Couldn't get the data from Discord API.")
return
user_guilds = json.loads(r.text)
bot_guilds = []
headers = {
'Authorization': 'Bot ' + constants.TOKEN
}
last_id = None
while True:
try:
if last_id:
r = requests.get(API_ENDPOINT + '/users/@me/guilds?after=' + last_id, headers=headers)
else:
r = requests.get(API_ENDPOINT + '/users/@me/guilds', headers=headers)
r.raise_for_status()
except requests.exceptions.HTTPError:
handler.logger.exception("Couldn't get the data from Discord API.")
handler.logger.debug(r.text)
handler.send_error(500, "Couldn't get the data from Discord API.")
return
tmp_guilds = json.loads(r.text)
if not tmp_guilds:
break
last_id = tmp_guilds[-1]["id"]
bot_guilds += tmp_guilds
if len(tmp_guilds) < 100:
break
common_guilds = [e for e in user_guilds for e2 in bot_guilds if e['id'] == e2['id']]
etag = handler.get_etag(common_guilds)
if not etag:
handler.send_error(304)
return
handler.send_object(common_guilds, etag)
| python |
from arena import auth
auth.signout()
| python |
import datetime
import time
import serial
if __name__ == "__main__":
ser = serial.Serial(
port='/dev/ttyACM0',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
while True:
byte_response = ser.readline()
char_response = byte_response.decode('UTF-8')
print(char_response)
| python |
RANDOM_SEED = 42
| python |
import re
text='isa python l earn and \n itis easy to'
#my_pat='^i[ts]'
#my_pat="learn$"
#my_pat=r"\blearn\b"
#my_pat=r"\Blearn\B"
my_pat=r"\n"
print(re.findall(my_pat,text)) | python |
from datetime import datetime
import os
import socket
import subprocess
import time
from celery import chain, chord
from celery.exceptions import Reject
import numpy as np
import csv
from .worker import simulate_pendulum_instance
from ..app import app
## Monitoring tasks
@app.task
def monitor_queues(ignore_result=True):
server_name = app.conf.MONITORING_SERVER_NAME
server_port = app.conf.MONITORING_SERVER_PORT
metric_prefix = app.conf.MONITORING_METRIC_PREFIX
queues_to_monitor = ('server', 'worker')
output = subprocess.check_output('rabbitmqctl -q list_queues name messages consumers', shell=True)
lines = (line.split() for line in output.splitlines())
data = ((queue, int(tasks), int(consumers)) for queue, tasks, consumers in lines if queue in queues_to_monitor)
timestamp = int(time.time())
metrics = []
for queue, tasks, consumers in data:
metric_base_name = "%s.queue.%s." % (metric_prefix, queue)
metrics.append("%s %d %d\n" % (metric_base_name + 'tasks', tasks, timestamp))
metrics.append("%s %d %d\n" % (metric_base_name + 'consumers', consumers, timestamp))
sock = socket.create_connection((server_name, server_port), timeout=10)
sock.sendall(''.join(metrics))
sock.close()
## Recording the experiment status
#ako je nesto vec racunao, on radi neke optimizacije
def get_experiment_status_filename(status):
return os.path.join(app.conf.STATUS_DIR, status)
def get_experiment_status_time():
"""Get the current local date and time, in ISO 8601 format (microseconds and TZ removed)"""
return datetime.now().replace(microsecond=0).isoformat()
@app.task
def record_experiment_status(status):
with open(get_experiment_status_filename(status), 'w') as fp:
fp.write(get_experiment_status_time() + '\n')
## Seeding the computations
def parametric_sweep(theta_resolution, tmax, dt):
# Pendulum rod lengths (m), bob masses (kg).
L1, L2 = 1.0, 1.0
m1, m2 = 1.0, 1.0
# Maximum time, time point spacings (all in s).
#tmax, dt = 30.0, 0.01
theta1_inits = np.linspace(0, 2*np.pi, theta_resolution)
theta2_inits = np.linspace(0, 2*np.pi, theta_resolution)
import itertools
t1t2_inits = itertools.product(theta1_inits, theta2_inits)
return ((L1, L2, m1, m2, tmax, dt, t1t2_i[0], t1t2_i[1]) for t1t2_i in t1t2_inits)
@app.task
def seed_computations(ignore_result=True):
#if os.path.exists(get_experiment_status_filename('started')):
#raise Reject('Computations have already been seeded!')
record_experiment_status.si('started').delay()
_tmax = app.conf.TMAX
_theta_res = app.conf.THETA_RESOLUTION
_dt = app.conf.DT
chord(
(
simulate_pendulum_instance.s(L1, L2, m1, m2, tmax, dt, theta1_init, theta2_init)
for (L1, L2, m1, m2, tmax, dt, theta1_init, theta2_init) in
parametric_sweep(_theta_res, _tmax, _dt)
),
store_results.s()
).delay()
@app.task
def store_results(solutions):
with open('/home/dpc.csv', 'wb') as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
csvwriter.writerow(["theta1_init", "theta2_init", "theta1_last", "theta2_last", "x1_last", "y1_last", "x2_last", "y2_last"])
for t1i, t2i, results in solutions:
theta1, theta2, x1, y1, x2, y2 = results #to je ono sto je solve izracunao
csvwriter.writerow([t1i, t2i, theta1[-1], theta2[-1], x1[-1], y1[-1], x2[-1], y2[-1]])
| python |
#!usr/bin/python
# --coding: utf-8 —**
# this is a inner script of subdata_by_dur.sh, which obtain a bash function
import sys
import os
from random import shuffle
def sub_set(srcdir):
f = open(srcdir+'/spk2utt', 'r')
spk2utt = f.readlines()
f.close()
f = open(srcdir+'/feats_vad.ark', 'r')
scp = f.readlines()
f.close()
sum = 0
for spk_line in spk2utt:
name = spk_line.strip().split()[0]
utts = spk_line.strip().split()[1:]
print("%s" % name)
for utt in utts:
for utt_line in scp:
if utt_line.strip().split()[0]== utt:
wavdir = utt_line.strip().split()[1]
dur = os.popen('soxi -D %s' % wavdir).read()
sum += float(dur.strip())
break
f.close()
print(sum)
def sub_set_vad(srcdir):
f = open(srcdir+'/spk2utt', 'r')
spk2utt = f.readlines()
f.close()
f = open(srcdir+'/feats_vad.ark', 'r')
scp = f.readlines()
f.close()
sum = 0
for spk_line in spk2utt:
name = spk_line.strip().split()[0]
utts = spk_line.strip().split()[1:]
print("%s" % name)
for utt in utts:
for utt_line in scp:
if utt_line.strip().split()[0]== utt:
wavlen = utt_line.strip().split()[1]
sum += int(wavlen)
break
f.close()
print(sum)
def main():
#srcdir = sys.argv[1]
#desdir = sys.argv[2]
srcdir = "/work9/cslt/kangjiawen/cslt-celeb/egs/i-vector/data/data/eval_enroll"
#sub_set(srcdir)
sub_set_vad(srcdir)
if __name__ =="__main__":
main()
| python |
#Escreva um programa que pergunte a quantidade de Km percorridos por um carro alugado
#e a quantidade de dias pelos quais ele foi alugado. Calcule o preço a pagar, sabendo que o carro custa R$60 por dia e R$0,15 por Km rodado.
from time import sleep #import sleep
print('\033[36m---------------ALUGUEL DE CARROS---------------\033[m') #titúlo
km = float(input('Quantos km foram percorridos com o carro? ')) #input de km percorridos pelo carro na variavek km
d = int(input('Por quantos dias o carro foi alugado? ')) #input dos dias de aluguel na variavel d
print('\033[36mPROCESSANDO...\033[m') #print para simular o processamento
sleep(1) #sleep
print(f'O carro percorreu \033[36m{km}km\033[m em \033[36m{d}\033[m dias, você terá que pagar \033[36mR${(km*0.15)+(d*60)}\033[m') #calculo e resultado
| python |
from app import db, ma
from app.mixins import CRUDMixin
from app.api.contact.models import Contact
from app.api.user.models import User
class Task(db.Model, CRUDMixin):
__tablename__ = 'tasks'
id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.String)
text = db.Column(db.String)
status = db.Column(db.String)
due_date = db.Column(db.String)
# Foreign keys
contact_id = db.Column(db.Integer, db.ForeignKey(Contact.id))
sales_id = db.Column(db.Integer, db.ForeignKey(User.id))
# Relationships
contact = db.relationship('Contact', backref="tasks")
sales = db.relationship('User', backref="tasks")
class TaskSchema(ma.SQLAlchemySchema):
class Meta:
model = Task
id = ma.auto_field()
type = ma.auto_field()
text = ma.auto_field()
status = ma.auto_field()
due_date = ma.auto_field()
# Foreign keys
contact_id = ma.auto_field()
sales_id = ma.auto_field()
task_schema = TaskSchema()
tasks_schema = TaskSchema(many=True) | python |
import numpy as np
import matplotlib.pyplot as plt
from pandas.stats.moments import rolling_mean, rolling_std
def plot(sample_file_name, window):
data = open(sample_file_name, 'r').read()
data = data.split('\n')
x, y = np.loadtxt(data, delimiter=';', unpack=True)
sma = rolling_mean(y, window)
roll_std = rolling_std(y, window)
ub = sma + (roll_std * 2)
lb = sma - (roll_std * 2)
plt.plot(x[window:], sma[window:], label='middle band', linewidth=0.3, alpha=0.95)
plt.plot(x[window:], ub[window:], label='upper band', linewidth=0.3, alpha=0.95)
plt.plot(x[window:], lb[window:], label='lower band', linewidth=0.3, alpha=0.95)
plt.fill_between(x, lb, ub, facecolor='grey', alpha=0.7)
plt.plot(x[window:], y[window:], label='plot', linewidth=1.3)
plt.xlim(x[window + 1], x[-1])
plt.legend()
plt.show()
if __name__ == "__main__":
plot('example/sample.csv', 20) | python |
from flask import Blueprint,render_template,request,flash,redirect,url_for,session,jsonify
from models import *
from utils.constand import admin_news_count
from utils.response_code import RET,error_map
import re
#生成密码
from werkzeug.security import generate_password_hash,check_password_hash
#初始化
admin_blue = Blueprint('admin',__name__)
#显示登陆页面
@admin_blue.route("/login",methods=['post','get'])
def login():
if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
print(username)
print(password)
if not all([username,password]):
flash('用户名和密码都必须输入')
else:
#用户名必须是数字,字母下划线5到8位
flag = re.match("\w{5,8}$",username)
# print(flag)
if flag == False:
flash('用户名不合法')
else:
admin = Admin.query.filter(Admin.name==username).first()
if not admin:
flash('用户不存在')
else:
flag = check_password_hash(admin.password_hash,password)
if flag:
session['username'] = username
return redirect(url_for('admin.index'))
else:
flash("密码错误")
return render_template('admin/login.html')
#初始化管理员
@admin_blue.route("/addadmin")
def add_admin():
password = generate_password_hash('123')
admin = Admin(name='admin',password_hash=password)
db.session.add(admin)
return 'ok'
# 显示后台管理页面
@admin_blue.route('/index')
def index():
admin_user = session.get('username')
if not admin_user:
return redirect(url_for('info.admin.admin.login'))
else:
return render_template('admin/index.html')
#点击新闻管理跳转的新闻管理分类页面,直接渲染出新闻管理分类页面
@admin_blue.route('/newscate',methods=['post','get'])
def newscate():
if request.method == 'POST':
mes = {}
id = request.form.get('id')
name = request.form.get('name')
if id:
news_type = News_type.query.filter(News_type.id==id).first()
if not news_type:
mes['code'] = 10050
mes['message'] = '没有此类信息'
else:
news_type.name=name
db.session.add(news_type)
mes['code'] = 200
mes['message'] = '修改成功'
return jsonify(mes)
else:
if name:
category=News_type.query.filter(News_type.name==name).first()
if category:
mes['code']=10010
mes['message'] = '分类以存在'
return jsonify(mes)
else:
news_type=News_type(name=name)
print(db)
db.session.add(news_type)
mes['code'] = 200
mes['message'] = '添加成功'
print(news_type)
return jsonify(mes)
else:
mes['code'] = 10020
mes['message'] = '不能为空'
return jsonify(mes)
category=News_type.query.all()
return render_template('admin/news_type.html',category=category)
#新闻分类删除
@admin_blue.route("/deletecate",methods=['post','get'])
def deletecate():
mes = {}
if request.method == "POST":
id=request.form.get('id')
news_type=News_type.query.filter(News_type.id==id).delete()
mes['code'] = 200
mes['message'] = '删除成功'
return jsonify(mes)
# 新闻分页,搜索列表
@admin_blue.route('/newsreview')
def newsreview():
current_page = 1
try:
page = int(request.args.get('page',0))
except:
page = 0
keyword = request.args.get('keyword')
#分页
if page>0:
current_page = page
page_count = admin_news_count
#搜索
if keyword:
news_list = News.query.filter(News.name.like('%'+keyword+'%')).paginate(current_page,page_count,False)
else:
keyword=''
news_list = News.query.paginate(current_page,page_count,False)
data = {'news_list':news_list.items,'current_page':news_list.page,'total_page':news_list.pages,'keyword':keyword}
return render_template('admin/news_review.html',data=data)
# #审核
# @admin_blue.route("/news_review_detail",methods=['post','get'])
# def news_review_detail():
# if request.method == 'POST':
# mes = {}
# #获取要更新的值
# id = request.form.get('id')
# action = request.form.get('action')
# reason = request.form.get('reason')
# print(action)
# #通过ID获取新闻
# news = News.query.filter(News.id == id).first()
# if news:
# #在审核成功的时候更新字段
# news.id_exam = int(action)
# #在审核失败的时候更新原因
# if int(action) == 2:
# news.reason = reason
# db.session.add(news)
# mes['errno'] = 200
# mes['errmsg'] = '审核成功'
# else:
# mes['errno'] = 10020
# mes['errmsg'] = '找不到该新闻'
# return jsonify(mes)
# id = request.args.get('id')
# news = News.query.filter(News.id == id).first()
# data = {'news':news}
# return render_template("admin/news_review_detail.html",data=data)
# 审核
@admin_blue.route("/news_review_detail",methods=['post','get'])
def news_review_detail():
if request.method=='POST':
mes={}
# 需要更新的值
id = request.form.get('id')
action = request.form.get('action')
reason = request.form.get('reason')
# 通过id获取新闻
news = News.query.filter(News.id==id).first()
if news:
# 存在更新字段
news.is_exam = int(action)
# 失败的时候更新原因
if int(action) == 2:
news.reason = reason
db.session.add(news)
mes['errno'] = RET.OK
mes['errmsg'] = error_map[RET.OK]
else:
mes['errno'] = 10010
mes['errmsg'] = '找不到新闻'
return jsonify(mes)
id = request.args.get('id')
news = News.query.filter(News.id==id).first()
data ={'news':news}
return render_template('admin/news_review_detail.html',data=data)
from datetime import timedelta
@admin_blue.route("/user_count",methods=['post','get'])
def user_count():
#获取总人数
total = User.query.count()
#每月活跃人数,从当月一号到现在
monthday = datetime.strftime(datetime.now(),"%Y-%m-01")
month_total = User.query.filter(User.update_time>=monthday).count()
#每月活跃人数,从早晨00到现在
day = datetime.strftime(datetime.now(),"%Y-%m-%d")
day_total = User.query.filter(User.update_time>=day).count()
datelist = []
daycount = []
for i in range(30,0,-1):
startime = datetime.strptime(day,'%Y-%m-%d') - timedelta(i)
endtime = datetime.strptime(day,'%Y-%m-%d') - timedelta(i-1)
dayc = User.query.filter(User.update_time>=startime,
User.update_time<=endtime).count()
datelist.append(datetime.strftime(startime,"%Y-%m-%d"))
daycount.append(dayc)
data = {'total':total,'month_total':month_total,'day_total':day_total,
'datelist':datelist,'daycount':daycount}
return render_template('admin/user_count.html',data=data)
@admin_blue.route("/user_list")
def user_list():
data = []
return render_template("admin/user_list.html",data=data)
| python |
import numpy as np
import config
import tensorflow as tf
DEBUG = False
def create_labels_overlap(feat_size, y_crops):
batch_labels, batch_weights = \
tf.py_func(create_labels_overlap_py,
[feat_size, tf.reshape(y_crops, [-1, 4]), (feat_size - 1)/2],
[tf.float32, tf.float32])
return batch_labels, batch_weights
def create_labels_overlap_py(feat_size, y_crops, orgin, random_select=False):
orig_size = feat_size*config.stride
x = np.arange(0, orig_size[0], config.stride)+config.stride/2
y = np.arange(0, orig_size[1], config.stride)+config.stride/2
x, y = np.meshgrid(x, y)
orgin = orgin*config.stride + config.stride/2
batch_labels, batch_weights, batch_keep = [], [], []
for gt_bb_cur in y_crops:
gt_size_cur = gt_bb_cur[2:4] - gt_bb_cur[0:2] + 1
gt_bb_cur_new = np.hstack([orgin - (gt_size_cur - 1) / 2, orgin + (gt_size_cur - 1) / 2])
sample_centers = np.vstack([x.ravel(), y.ravel(), x.ravel(), y.ravel()]).transpose()
sample_bboxes = sample_centers + np.hstack([-(gt_size_cur-1)/2, (gt_size_cur-1)/2])
overlaps = bbox_overlaps(sample_bboxes, gt_bb_cur_new)
pos_idxes = overlaps > config.overlap_thre
neg_idxes = overlaps < config.overlap_thre
labels = -np.ones(np.prod(feat_size), dtype=np.float32)
labels[pos_idxes] = 1
labels[neg_idxes] = 0
labels = np.reshape(labels, feat_size)
num_pos = np.count_nonzero(labels == 1)
num_neg = np.count_nonzero(labels == 0)
if DEBUG:
print(gt_bb_cur)
print((gt_bb_cur[0:2]+gt_bb_cur[2:4])/2)
print('Positive samples:', num_pos, 'Negative samples:', num_neg)
weights = np.zeros(feat_size, dtype=np.float32)
if num_pos != 0:
weights[labels == 1] = 0.5 / num_pos
if num_neg != 0:
weights[labels == 0] = 0.5 / num_neg
batch_weights.append(np.expand_dims(weights, 0))
batch_labels.append(np.expand_dims(labels, 0))
batch_labels = np.concatenate(batch_labels, 0)
batch_weights = np.concatenate(batch_weights, 0)
return batch_labels, batch_weights
def bbox_overlaps(sample_bboxes, gt_bbox):
lt = np.maximum(sample_bboxes[:, 0:2], gt_bbox[0:2])
rb = np.minimum(sample_bboxes[:, 2:4], gt_bbox[2:4])
inter_area = np.maximum(rb - lt + 1, 0)
inter_area = np.prod(inter_area, 1)
union_area = np.prod(sample_bboxes[:, 2:4] - sample_bboxes[:, 0:2] + 1, 1) + np.prod(gt_bbox[2:4]-gt_bbox[0:2]+1, 0) - inter_area
return inter_area / union_area
if __name__ == '__main__':
feat_size = np.array([255, 255])
y_bboxes = np.array([[100, 100, 155, 155], [15,15, 50, 100], [15,15, 100, 100]])
batch_labels, batch_cls_w = create_labels_overlap_py(feat_size, y_bboxes, np.array([128, 128]), True) | python |
#-----------------------------------------------------------------------------
"""
SoC file for Nordic devices
Read in the SVD file for a named SoC.
Run fixup functions to correct any SVD inadequecies.
"""
#-----------------------------------------------------------------------------
import soc
import cmregs
#-----------------------------------------------------------------------------
# build a database of SoC devices
class soc_info(object):
def __init__(self):
pass
soc_db = {}
#-----------------------------------------------------------------------------
# GPIO Registers
_gpio_dir_enumset = (
('Input', 0, None),
('Output', 1, None),
)
_gpio_pin_cnf_fieldset = (
('SENSE',17,16, None, 'Pin sensing mechanism'),
('DRIVE',10,8, None, 'Drive configuration'),
('PULL',3,2, None, 'Pull configuration'),
('INPUT',1,1, None, 'Connect/Disconnect Input Buffer'),
('DIR',0,0, _gpio_dir_enumset, 'Pin direction'),
)
_gpio_dir_fieldset = (
('PIN0', 0, 0, _gpio_dir_enumset, 'Px.0 pin'),
('PIN1', 1, 1, _gpio_dir_enumset, 'Px.1 pin'),
('PIN2', 2, 2, _gpio_dir_enumset, 'Px.2 pin'),
('PIN3', 3, 3, _gpio_dir_enumset, 'Px.3 pin'),
('PIN4', 4, 4, _gpio_dir_enumset, 'Px.4 pin'),
('PIN5', 5, 5, _gpio_dir_enumset, 'Px.5 pin'),
('PIN6', 6, 6, _gpio_dir_enumset, 'Px.6 pin'),
('PIN7', 7, 7, _gpio_dir_enumset, 'Px.7 pin'),
('PIN8', 8, 8, _gpio_dir_enumset, 'Px.8 pin'),
('PIN9', 9, 9, _gpio_dir_enumset, 'Px.9 pin'),
('PIN10', 10, 10, _gpio_dir_enumset, 'Px.10 pin'),
('PIN11', 11, 11, _gpio_dir_enumset, 'Px.11 pin'),
('PIN12', 12, 12, _gpio_dir_enumset, 'Px.12 pin'),
('PIN13', 13, 13, _gpio_dir_enumset, 'Px.13 pin'),
('PIN14', 14, 14, _gpio_dir_enumset, 'Px.14 pin'),
('PIN15', 15, 15, _gpio_dir_enumset, 'Px.15 pin'),
('PIN16', 16, 16, _gpio_dir_enumset, 'Px.16 pin'),
('PIN17', 17, 17, _gpio_dir_enumset, 'Px.17 pin'),
('PIN18', 18, 18, _gpio_dir_enumset, 'Px.18 pin'),
('PIN19', 19, 19, _gpio_dir_enumset, 'Px.19 pin'),
('PIN20', 20, 20, _gpio_dir_enumset, 'Px.20 pin'),
('PIN21', 21, 21, _gpio_dir_enumset, 'Px.21 pin'),
('PIN22', 22, 22, _gpio_dir_enumset, 'Px.22 pin'),
('PIN23', 23, 23, _gpio_dir_enumset, 'Px.23 pin'),
('PIN24', 24, 24, _gpio_dir_enumset, 'Px.24 pin'),
('PIN25', 25, 25, _gpio_dir_enumset, 'Px.25 pin'),
('PIN26', 26, 26, _gpio_dir_enumset, 'Px.26 pin'),
('PIN27', 27, 27, _gpio_dir_enumset, 'Px.27 pin'),
('PIN28', 28, 28, _gpio_dir_enumset, 'Px.28 pin'),
('PIN29', 29, 29, _gpio_dir_enumset, 'Px.29 pin'),
('PIN30', 30, 30, _gpio_dir_enumset, 'Px.30 pin'),
('PIN31', 31, 31, _gpio_dir_enumset, 'Px.31 pin'),
)
_gpio_regset = (
('OUT' , 32, 0x504, None, 'Write GPIO port'),
('OUTSET' , 32, 0x508, None, 'Set individual bits in GPIO port'),
('OUTCLR' , 32, 0x50c, None, 'Clear individual bits in GPIO port'),
('IN' , 32, 0x510, None, 'Read GPIO port'),
('DIR' , 32, 0x514, _gpio_dir_fieldset, 'Direction of GPIO pins'),
('DIRSET' , 32, 0x518, None, 'DIR set register'),
('DIRCLR' , 32, 0x51c, None, 'DIR clear register'),
('LATCH' , 32, 0x520, None, 'Latch for PIN_CNF[n].SENSE'),
('DETECTMODE' , 32, 0x524, None, 'Select between DETECT/LDETECT'),
('PIN_CNF0' , 32, 0x700, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF1' , 32, 0x704, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF2' , 32, 0x708, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF3' , 32, 0x70c, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF4' , 32, 0x710, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF5' , 32, 0x714, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF6' , 32, 0x718, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF7' , 32, 0x71c, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF8' , 32, 0x720, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF9' , 32, 0x724, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF10' , 32, 0x728, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF11' , 32, 0x72c, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF12' , 32, 0x730, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF13' , 32, 0x734, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF14' , 32, 0x738, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF15' , 32, 0x73c, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF16' , 32, 0x740, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF17' , 32, 0x744, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF18' , 32, 0x748, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF19' , 32, 0x74c, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF20' , 32, 0x750, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF21' , 32, 0x754, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF22' , 32, 0x758, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF23' , 32, 0x75c, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF24' , 32, 0x760, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF25' , 32, 0x764, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF26' , 32, 0x768, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF27' , 32, 0x76c, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF28' , 32, 0x770, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF29' , 32, 0x774, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF30' , 32, 0x778, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
('PIN_CNF31' , 32, 0x77c, _gpio_pin_cnf_fieldset, 'Configuration of GPIO pins'),
)
#-----------------------------------------------------------------------------
# nRF51822
def nRF51822_fixup(d):
d.soc_name = 'nRF51822'
d.cpu_info.deviceNumInterrupts = 32
# memory and misc peripherals
d.insert(soc.make_peripheral('ram', 0x20000000, 16 << 10, None, 'Data RAM'))
# This device has FICR.CLENR0 = 0xffffffff indicating that the code 0 region does not exist
d.insert(soc.make_peripheral('flash', 0, 256 << 10, None, 'Code FLASH'))
s = soc_info()
s.name = 'nRF51822'
s.svd = 'nrf51'
s.fixups = (nRF51822_fixup, cmregs.cm0_fixup)
soc_db[s.name] = s
#-----------------------------------------------------------------------------
# nRF52832
def nRF52832_fixup(d):
d.soc_name = 'nRF52832'
d.cpu_info.nvicPrioBits = 3
d.cpu_info.deviceNumInterrupts = 39 # Note: reference manual has 37, svd file has 39
# remove some core peripherals - we'll replace them in the cpu fixup
d.remove(d.FPU)
# memory and misc peripherals
d.insert(soc.make_peripheral('ram', 0x20000000, 64 << 10, None, 'Data RAM'))
d.insert(soc.make_peripheral('flash', 0, 512 << 10, None, 'Code FLASH'))
s = soc_info()
s.name = 'nRF52832'
s.svd = 'nrf52'
s.fixups = (nRF52832_fixup, cmregs.cm4_fixup)
soc_db[s.name] = s
#-----------------------------------------------------------------------------
# nRF52833
def nRF52833_fixup(d):
d.soc_name = 'nRF52833'
d.cpu_info.nvicPrioBits = 3
d.cpu_info.deviceNumInterrupts = 39 # Note: reference manual has 37, svd file has 39
# remove some core peripherals - we'll replace them in the cpu fixup
d.remove(d.FPU)
# memory and misc peripherals
d.insert(soc.make_peripheral('ram', 0x20000000, 128 << 10, None, 'Data RAM'))
d.insert(soc.make_peripheral('flash', 0, 512 << 10, None, 'Code FLASH'))
# 2nd gpio port
d.insert(soc.make_peripheral('P1', 0x50000300, 4 << 10, _gpio_regset, 'GPIO Port 2'))
s = soc_info()
s.name = 'nRF52833'
s.svd = 'nrf52'
s.fixups = (nRF52833_fixup, cmregs.cm4_fixup)
soc_db[s.name] = s
#-----------------------------------------------------------------------------
def get_device(ui, name):
"""return the device structure for the named SoC"""
if not name in soc_db:
assert False, 'unknown SoC name %s' % name
return None
info = soc_db[name]
svd_file = './vendor/nordic/svd/%s.svd.gz' % info.svd
ui.put('%s: compiling %s\n' % (name, svd_file))
device = soc.build_device(svd_file)
for f in info.fixups:
f(device)
return device
#-----------------------------------------------------------------------------
| python |
import json
from app.inference import app
def test_uploadfile():
client = app.test_client()
response = client.post("/upload_file", data=json.dumps(dict(f='f')))
assert response.status_code == 400
response1 = client.get("/upload_file", data=json.dumps(dict(f='f')))
assert response1.status_code == 405
| python |
from unittest import result
import requests
from urllib.parse import urljoin
from datetime import datetime, timedelta
import pandas as pd
import numpy as np
import json
#import statsmodels.api as sm
#import statsmodels.formula.api as smf
from PyBlakemere.PyMemoize.MemoizationDecorator import memoize
from PyBlakemere.PyMemoize.CacheBackendDisk import DiskCacheBackend
from pathlib import Path
class PrometheusQueryClient:
def __init__(self, url, cache_path=None, cache_encrypt_at_rest=False, cache_ttl=3600, ssl_verify=True, auto_get_server_metrics=True):
self.url = url
self.ssl_verify = ssl_verify
self.metrics = None
# Dynamically generate the _do_query_cache function, with or without caching.
if(cache_path and False):
@memoize(DiskCacheBackend(cache_path, encrypt_at_rest=cache_encrypt_at_rest), maxttl=cache_ttl, is_class_method=True)
def query_function(self, path, params):
return self.__do_query_direct(self, path, params)
else:
def query_function(self, path, params):
return self.__do_query_direct(self, path, params)
setattr(self, '__query_function', query_function)
if(auto_get_server_metrics):
self._get_all_metrics()
def __do_query_direct(self, path, params):
resp = requests.get(urljoin(self.url, path), params=params, verify=self.ssl_verify)
response = resp.json()
if response['status'] != 'success':
raise RuntimeError('{errorType}: {error}'.format_map(response))
return response['data']
def _do_query(self, path, params):
results = self.__query_function(path, params)
return results
def _get_all_metrics(self):
resp = requests.get(self.url + '/api/v1/label/__name__/values', verify=self.ssl_verify)
content = json.loads(resp.content.decode('UTF-8'))
if content['status'] != 'success':
raise RuntimeError('{errorType}: {error}'.format(resp.status_code))
self.metrics = [ item for item in content.get('data', {}) ]
return
def get_metrics_starting_with(self, targets):
results = []
for item in self.metrics:
if any(target in item for target in targets):
results.append(item)
return results
@staticmethod
def _datetime_to_str(t):
return t.strftime('%Y-%m-%dT%H:%M:%SZ') if (isinstance(t, datetime)) else t
def query_range(self, query, start, end, step, timeout=None):
# Make sure our start and end times are as strings rather than
start = PrometheusQueryClient._datetime_to_str(start)
end = PrometheusQueryClient._datetime_to_str(end)
# Build the params
params = {'query': query, 'start': start, 'end': end, 'step': step}
if (timeout and not params.get('timeout', False)): # FIXME: This test doesn't work. Always does the update
params.update({'timeout': timeout})
# Run the query.
# TODO: Externalize the api string
results = self._do_query('api/v1/query_range', params)
return results
def get_general(self, query, start=None, end=None, step=None):
enddt = datetime.now()
startdt = enddt - timedelta(hours = 1)
if (not start):
start = startdt.strftime('%Y-%m-%dT%H:%M:%SZ')
else:
startdt = datetime.strptime(start, '%Y-%m-%dT%H:%M:%SZ')
if(not end):
end = enddt.strftime('%Y-%m-%dT%H:%M:%SZ')
else:
enddt = datetime.strptime(end, '%Y-%m-%dT%H:%M:%SZ')
if (not step):
step = '{}s'.format( round((enddt.timestamp() - startdt.timestamp()) / 500) )
# Correct step size that is so small it will cause an error
if ( ((enddt.timestamp() - startdt.timestamp()) / 500) > 11000):
step = '{}s'.format( np.floor((enddt.timestamp() - startdt.timestamp()) / 11000) )
print('Warning: step size too small. Setting to {}s'.format(step))
results = self.query_range(query, start, end, step)
return results
def get_without_deltas(self, query, start=None, end=None, step=None):
results = self.get_general(query, start, end, step)
data = { '{} - {}'.format(r['metric']['__name__'], r['metric']['instance']):
pd.Series((np.float64(v[1]) for v in r['values']), index=(pd.Timestamp(v[0], unit='s') for v in r['values']))
for r in results['result']}
df = pd.DataFrame(data)
return (results, df)
def get_with_deltas(self, query, start=None, end=None, step=None):
(results, df) = self.get_without_deltas(query, start, end, step)
for col in df.columns:
tmp = [ ]
items = df[col].to_list()
for (index, _) in enumerate(items):
if (index == 0):
tmp.append(0)
else:
tmp.append( items[index] - items[index - 1] )
df['delta_{}'.format(col)] = tmp
return (results, df)
def get_metric(self, metric, start=None, end=None, step=None):
if (not metric in self.metrics):
raise ValueError("Metric '{}' is unknown".format(metric))
is_cummulative = any(item in metric for item in ['_total'])
if (is_cummulative):
results = self.get_with_deltas(metric, start, end, step)
else:
results = self.get_without_deltas(metric, start, end, step)
return results
if __name__ == '__main__':
import urllib3
urllib3.disable_warnings()
api_url = "https://azlappjaegrs1.mfcgd.com/prometheus/"
js = PrometheusQueryClient(api_url, cache_path='./.cache_tmp/', cache_ttl=3600)
targets = [ 'node_network_carrier_changes_total', 'node_network_transmit_bytes_total' ]
metrics = js.get_metrics_starting_with(targets)
starttime = '2022-02-16T10:51:32Z'
endtime = '2022-02-17T10:59:22Z'
results = {}
for metric in metrics:
print("Getting results for metric '{}'".format(metric))
results[metric] = {}
(results[metric]['data'], results[metric]['df']) = js.get_metric(metric, start=starttime, end=endtime)
| python |
# -*- coding: utf-8 -*-
from inferbeddings.knowledgebase.base import Fact, KnowledgeBaseParser
__all__ = ['Fact', 'KnowledgeBaseParser']
| python |
def fr_mean(spike_trains, **kwargs):
pass
| python |
#!/usr/bin/env python
#
# Start the Rhinohawk mission
#
import sys
from rh_autonomy.util import get_proxy
from rh_msgs.srv import StartMission
start_mission = get_proxy('/rh/command/start_mission', StartMission)
res = start_mission()
if res and res.success:
print("Successfully started mission")
sys.exit(0)
else:
print("Problem starting mission")
sys.exit(1)
| python |
# -*- coding: utf-8 -*-
import pytest
import rsa # type: ignore
from mtpylon import long
from mtpylon.crypto.rsa_fingerprint import get_fingerprint
public_keys_with_fingerprint = [
pytest.param(
rsa.PublicKey.load_pkcs1(
"""
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAwVACPi9w23mF3tBkdZz+zwrzKOaaQdr01vAbU4E1pvkfj4sqDsm6
lyDONS789sVoD/xCS9Y0hkkC3gtL1tSfTlgCMOOul9lcixlEKzwKENj1Yz/s7daS
an9tqw3bfUV/nqgbhGX81v/+7RFAEd+RwFnK7a+XYl9sluzHRyVVaTTveB2GazTw
Efzk2DWgkBluml8OREmvfraX3bkHZJTKX4EQSjBbbdJ2ZXIsRrYOXfaA+xayEGB+
8hdlLmAjbCVfaigxX0CDqWeR1yFL9kwd9P0NsZRPsmoqVwMbMu7mStFai6aIhc3n
Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
-----END RSA PUBLIC KEY-----
""",
),
long(-4344800451088585951),
id='c3b42b026ce86b21'
),
pytest.param(
rsa.PublicKey.load_pkcs1_openssl_pem(
"""
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAruw2yP/BCcsJliRoW5eB
VBVle9dtjJw+OYED160Wybum9SXtBBLXriwt4rROd9csv0t0OHCaTmRqBcQ0J8fx
hN6/cpR1GWgOZRUAiQxoMnlt0R93LCX/j1dnVa/gVbCjdSxpbrfY2g2L4frzjJvd
l84Kd9ORYjDEAyFnEA7dD556OptgLQQ2e2iVNq8NZLYTzLp5YpOdO1doK+ttrltg
gTCy5SrKeLoCPPbOgGsdxJxyz5KKcZnSLj16yE5HvJQn0CNpRdENvRUXe6tBP78O
39oJ8BTHp9oIjd6XWXAsp2CvK45Ol8wFXGF710w9lwCGNbmNxNYhtIkdqfsEcwR5
JwIDAQAB
-----END PUBLIC KEY-----
"""
),
long(0x0bc35f3509f7b7a5),
id='0bc35f3509f7b7a5'
),
pytest.param(
rsa.PublicKey.load_pkcs1_openssl_pem(
"""
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvfLHfYH2r9R70w8prHbl
Wt/nDkh+XkgpflqQVcnAfSuTtO05lNPspQmL8Y2XjVT4t8cT6xAkdgfmmvnvRPOO
KPi0OfJXoRVylFzAQG/j83u5K3kRLbae7fLccVhKZhY46lvsueI1hQdLgNV9n1cQ
3TDS2pQOCtovG4eDl9wacrXOJTG2990VjgnIKNA0UMoP+KF03qzryqIt3oTvZq03
DyWdGK+AZjgBLaDKSnC6qD2cFY81UryRWOab8zKkWAnhw2kFpcqhI0jdV5QaSCEx
vnsjVaX0Y1N0870931/5Jb9ICe4nweZ9kSDF/gip3kWLG0o8XQpChDfyvsqB9OLV
/wIDAQAB
-----END PUBLIC KEY-----
"""
),
long(0x15ae5fa8b5529542),
id="15ae5fa8b5529542"
),
pytest.param(
rsa.PublicKey.load_pkcs1_openssl_pem(
"""
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs/ditzm+mPND6xkhzwFI
z6J/968CtkcSE/7Z2qAJiXbmZ3UDJPGrzqTDHkO30R8VeRM/Kz2f4nR05GIFiITl
4bEjvpy7xqRDspJcCFIOcyXm8abVDhF+th6knSU0yLtNKuQVP6voMrnt9MV1X92L
GZQLgdHZbPQz0Z5qIpaKhdyA8DEvWWvSUwwc+yi1/gGaybwlzZwqXYoPOhwMebzK
Uk0xW14htcJrRrq+PXXQbRzTMynseCoPIoke0dtCodbA3qQxQovE16q9zz4Otv2k
4j63cz53J+mhkVWAeWxVGI0lltJmWtEYK6er8VqqWot3nqmWMXogrgRLggv/Nbbo
oQIDAQAB
-----END PUBLIC KEY-----
"""
),
long(-5859577972006586033),
id="aeae98e13cd7f94f"
),
pytest.param(
rsa.PublicKey.load_pkcs1_openssl_pem(
"""
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvmpxVY7ld/8DAjz6F6q0
5shjg8/4p6047bn6/m8yPy1RBsvIyvuDuGnP/RzPEhzXQ9UJ5Ynmh2XJZgHoE9xb
nfxL5BXHplJhMtADXKM9bWB11PU1Eioc3+AXBB8QiNFBn2XI5UkO5hPhbb9mJpjA
9Uhw8EdfqJP8QetVsI/xrCEbwEXe0xvifRLJbY08/Gp66KpQvy7g8w7VB8wlgePe
xW3pT13Ap6vuC+mQuJPyiHvSxjEKHgqePji9NP3tJUFQjcECqcm0yV7/2d0t/pbC
m+ZH1sadZspQCEPPrtbkQBlvHb4OLiIWPGHKSMeRFvp3IWcmdJqXahxLCUS1Eh6M
AQIDAQAB
-----END PUBLIC KEY-----
"""
),
long(0x5a181b2235057d98),
id="5a181b2235057d98"
),
]
@pytest.mark.parametrize(
'key,fingerprint',
public_keys_with_fingerprint
)
def test_get_fingerprint(key, fingerprint):
assert get_fingerprint(key) == fingerprint
| python |
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
from silksnake.remote.proto import kv_pb2 as silksnake_dot_remote_dot_proto_dot_kv__pb2
class KVStub(object):
"""Provides methods to access key-value data
"""
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.Seek = channel.stream_stream(
'/remote.KV/Seek',
request_serializer=silksnake_dot_remote_dot_proto_dot_kv__pb2.SeekRequest.SerializeToString,
response_deserializer=silksnake_dot_remote_dot_proto_dot_kv__pb2.Pair.FromString,
)
class KVServicer(object):
"""Provides methods to access key-value data
"""
def Seek(self, request_iterator, context):
"""open a cursor on given position of given bucket
if streaming requested - streams all data: stops if client's buffer is full, resumes when client read enough from buffer
if streaming not requested - streams next data only when clients sends message to bi-directional channel
no full consistency guarantee - server implementation can close/open underlying db transaction at any time
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_KVServicer_to_server(servicer, server):
rpc_method_handlers = {
'Seek': grpc.stream_stream_rpc_method_handler(
servicer.Seek,
request_deserializer=silksnake_dot_remote_dot_proto_dot_kv__pb2.SeekRequest.FromString,
response_serializer=silksnake_dot_remote_dot_proto_dot_kv__pb2.Pair.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'remote.KV', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
# This class is part of an EXPERIMENTAL API.
class KV(object):
"""Provides methods to access key-value data
"""
@staticmethod
def Seek(request_iterator,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.stream_stream(request_iterator, target, '/remote.KV/Seek',
silksnake_dot_remote_dot_proto_dot_kv__pb2.SeekRequest.SerializeToString,
silksnake_dot_remote_dot_proto_dot_kv__pb2.Pair.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
| python |
#!/usr/bin/env python3
"""
Script to call api endpoints
Author: Megan McGee
Date: October 9, 2021
"""
import requests
import os
import json
with open('config.json','r') as f:
config = json.load(f)
model_path = os.path.join(config['output_model_path'])
# Specify a URL that resolves to your workspace
URL = "http://127.0.0.1:8000/"
# Call each API endpoint and store the responses
response1 = requests.get(URL + 'prediction?filepath=/testdata/testdata.csv').content
response2 = requests.get(URL + 'scoring').content
response3 = requests.get(URL + 'summarystats').content
response4 = requests.get(URL + 'diagnostics').content
# Combine all API responses
responses = str(response1) + '\n' + str(response2) + '\n' + str(response3) + '\n' + str(response4)
# Write the responses to your workspace
with open(os.path.join(os.getcwd(), model_path, 'apireturns.txt'), 'w') as f:
f.write(responses)
| python |
from django.db import models
class Tag(models.Model):
identifier = models.CharField(max_length=100, unique=True)
description = models.TextField(blank=True, default='')
meta = models.TextField(blank=True, default='')
is_abstract = models.BooleanField(blank=True, default=False)
"""Abstract tags are not regarded when checking for untagged data points"""
# data_points
def __str__(self):
return (
f'<{self.__class__.__name__}'
f'{" [abstract]" if self.is_abstract else ""} {self.identifier}>'
)
| python |
'''This module contains the ComplexityVisitor class which is where all the
analysis concerning Cyclomatic Complexity is done. There is also the class
HalsteadVisitor, that counts Halstead metrics.'''
import ast
import operator
import collections
# Helper functions to use in combination with map()
GET_COMPLEXITY = operator.attrgetter('complexity')
GET_REAL_COMPLEXITY = operator.attrgetter('real_complexity')
NAMES_GETTER = operator.attrgetter('name', 'asname')
GET_ENDLINE = operator.attrgetter('endline')
# print("----------------------- SAM : START -----------------------")
BaseFunc = collections.namedtuple('Function', ['name', 'lineno', 'col_offset',
'endline', 'is_method',
'classname', 'closures',
'complexity', 'cloc'])
# print("----------------------- SAM : END -----------------------")
BaseClass = collections.namedtuple('Class', ['name', 'lineno', 'col_offset',
'endline', 'methods',
'inner_classes',
'real_complexity'])
def code2ast(source):
'''Convert a string object into an AST object.
This function is retained for backwards compatibility, but it no longer
attemps any conversions. It's equivalent to a call to ``ast.parse``.
'''
return ast.parse(source)
class Function(BaseFunc):
'''Object represeting a function block.'''
@property
def letter(self):
'''The letter representing the function. It is `M` if the function is
actually a method, `F` otherwise.
'''
return 'M' if self.is_method else 'F'
@property
def fullname(self):
'''The full name of the function. If it is a method, then the full name
is:
{class name}.{method name}
Otherwise it is just the function name.
'''
if self.classname is None:
return self.name
return '{0}.{1}'.format(self.classname, self.name)
def __str__(self):
'''String representation of a function block.'''
return '{0} {1}:{2}->{3} {4} - {5}'.format(self.letter, self.lineno,
self.col_offset,
self.endline,
self.fullname,
self.complexity)
class Class(BaseClass):
'''Object representing a class block.'''
letter = 'C'
@property
def fullname(self):
'''The full name of the class. It is just its name. This attribute
exists for consistency (see :data:`Function.fullname`).
'''
return self.name
@property
def complexity(self):
'''The average complexity of the class. It corresponds to the average
complexity of its methods plus one.
'''
if not self.methods:
return self.real_complexity
methods = len(self.methods)
return int(self.real_complexity / float(methods)) + (methods > 1)
def __str__(self):
'''String representation of a class block.'''
return '{0} {1}:{2}->{3} {4} - {5}'.format(self.letter, self.lineno,
self.col_offset,
self.endline, self.name,
self.complexity)
class CodeVisitor(ast.NodeVisitor):
'''Base class for every NodeVisitors in `radon.visitors`. It implements a
couple utility class methods and a static method.
'''
@staticmethod
def get_name(obj):
'''Shorthand for ``obj.__class__.__name__``.'''
return obj.__class__.__name__
@classmethod
def from_code(cls, code, **kwargs):
'''Instanciate the class from source code (string object). The
`**kwargs` are directly passed to the `ast.NodeVisitor` constructor.
'''
return cls.from_ast(code2ast(code), **kwargs)
@classmethod
def from_ast(cls, ast_node, **kwargs):
'''Instantiate the class from an AST node. The `**kwargs` are
directly passed to the `ast.NodeVisitor` constructor.
'''
visitor = cls(**kwargs)
visitor.visit(ast_node)
return visitor
class ComplexityVisitor(CodeVisitor):
'''A visitor that keeps track of the cyclomatic complexity of
the elements.
:param to_method: If True, every function is treated as a method. In this
case the *classname* parameter is used as class name.
:param classname: Name of parent class.
:param off: If True, the starting value for the complexity is set to 1,
otherwise to 0.
'''
def __init__(self, to_method=False, classname=None, off=True,
no_assert=False):
self.off = off
self.complexity = 1 if off else 0
self.functions = []
self.classes = []
self.to_method = to_method
self.classname = classname
self.no_assert = no_assert
self._max_line = float('-inf')
#print("----------------------- SAM : START -----------------------")
self.func_line_numbers = set()
#print("----------------------- SAM : END -----------------------")
@property
def functions_complexity(self):
'''The total complexity from all functions (i.e. the total number of
decision points + 1).
This is *not* the sum of all the complexity from the functions. Rather,
it's the complexity of the code *inside* all the functions.
'''
return sum(map(GET_COMPLEXITY, self.functions)) - len(self.functions)
@property
def classes_complexity(self):
'''The total complexity from all classes (i.e. the total number of
decision points + 1).
'''
return sum(map(GET_REAL_COMPLEXITY, self.classes)) - len(self.classes)
@property
def total_complexity(self):
'''The total complexity. Computed adding up the visitor complexity, the
functions complexity, and the classes complexity.
'''
return (self.complexity + self.functions_complexity +
self.classes_complexity + (not self.off))
@property
def blocks(self):
'''All the blocks visited. These include: all the functions, the
classes and their methods. The returned list is not sorted.
'''
blocks = []
blocks.extend(self.functions)
for cls in self.classes:
blocks.append(cls)
blocks.extend(cls.methods)
return blocks
@property
def max_line(self):
'''The maximum line number among the analyzed lines.'''
return self._max_line
@max_line.setter
def max_line(self, value):
'''The maximum line number among the analyzed lines.'''
if value > self._max_line:
self._max_line = value
def generic_visit(self, node):
'''Main entry point for the visitor.'''
# Get the name of the class
name = self.get_name(node)
if hasattr(node, 'lineno'):
# print("----------------------- SAM : START -----------------------")
# print(node, name, node.lineno)
self.func_line_numbers.add(node.lineno)
# print("----------------------- SAM : END -----------------------")
# Check for a lineno attribute
if hasattr(node, 'lineno'):
self.max_line = node.lineno
# The Try/Except block is counted as the number of handlers
# plus the `else` block.
# In Python 3.3 the TryExcept and TryFinally nodes have been merged
# into a single node: Try
if name in ('Try', 'TryExcept'):
self.complexity += len(node.handlers) + len(node.orelse)
elif name == 'BoolOp':
self.complexity += len(node.values) - 1
# Ifs, with and assert statements count all as 1.
# Note: Lambda functions are not counted anymore, see #68
elif name in ('If', 'IfExp'):
self.complexity += 1
# The For and While blocks count as 1 plus the `else` block.
elif name in ('For', 'While', 'AsyncFor'):
self.complexity += bool(node.orelse) + 1
# List, set, dict comprehensions and generator exps count as 1 plus
# the `if` statement.
elif name == 'comprehension':
self.complexity += len(node.ifs) + 1
super(ComplexityVisitor, self).generic_visit(node)
def visit_Assert(self, node):
'''When visiting `assert` statements, the complexity is increased only
if the `no_assert` attribute is `False`.
'''
self.complexity += not self.no_assert
def visit_AsyncFunctionDef(self, node):
'''Async function definition is the same thing as the synchronous
one.
'''
self.visit_FunctionDef(node)
def visit_FunctionDef(self, node):
'''When visiting functions a new visitor is created to recursively
analyze the function's body.
'''
# The complexity of a function is computed taking into account
# the following factors: number of decorators, the complexity
# the function's body and the number of closures (which count
# double).
closures = []
body_complexity = 1
# print("----------------------- SAM : START -----------------------")
total_lines = 0
#print("----------------------- SAM : END -----------------------")
for child in node.body:
visitor = ComplexityVisitor(off=False, no_assert=self.no_assert)
visitor.visit(child)
closures.extend(visitor.functions)
# Add general complexity but not closures' complexity, see #68
body_complexity += visitor.complexity
#print("----------------------- SAM : START -----------------------")
# print(visitor.func_line_numbers)
total_lines += len(visitor.func_line_numbers)
# line_numbers_set.add(visitor.)
#print("----------------------- SAM : END -----------------------")
func = Function(node.name, node.lineno, node.col_offset,
max(node.lineno, visitor.max_line), self.to_method,
self.classname, closures, body_complexity, total_lines)
print("----------------------- SAM : START -----------------------")
print(str(func), total_lines)
print("----------------------- SAM : END -----------------------")
self.functions.append(func)
def visit_ClassDef(self, node):
'''When visiting classes a new visitor is created to recursively
analyze the class' body and methods.
'''
# The complexity of a class is computed taking into account
# the following factors: number of decorators and the complexity
# of the class' body (which is the sum of all the complexities).
methods = []
# According to Cyclomatic Complexity definition it has to start off
# from 1.
body_complexity = 1
classname = node.name
visitors_max_lines = [node.lineno]
inner_classes = []
for child in node.body:
visitor = ComplexityVisitor(True, classname, off=False,
no_assert=self.no_assert)
visitor.visit(child)
methods.extend(visitor.functions)
body_complexity += (visitor.complexity +
visitor.functions_complexity +
len(visitor.functions))
visitors_max_lines.append(visitor.max_line)
inner_classes.extend(visitor.classes)
cls = Class(classname, node.lineno, node.col_offset,
max(visitors_max_lines + list(map(GET_ENDLINE, methods))),
methods, inner_classes, body_complexity)
self.classes.append(cls)
class HalsteadVisitor(CodeVisitor):
'''Visitor that keeps track of operators and operands, in order to compute
Halstead metrics (see :func:`radon.metrics.h_visit`).
'''
# As of Python 3.8 Num/Str/Bytes/NameConstat
# are now in a common node Constant.
types = {"Num": "n", "Name": "id", "Attribute": "attr", "Constant": "value"}
def __init__(self, context=None):
'''*context* is a string used to keep track the analysis' context.'''
self.operators_seen = set()
self.operands_seen = set()
self.operators = 0
self.operands = 0
self.context = context
# A new visitor is spawned for every scanned function.
self.function_visitors = []
@property
def distinct_operators(self):
'''The number of distinct operators.'''
return len(self.operators_seen)
@property
def distinct_operands(self):
'''The number of distinct operands.'''
return len(self.operands_seen)
def dispatch(meth):
'''This decorator does all the hard work needed for every node.
The decorated method must return a tuple of 4 elements:
* the number of operators
* the number of operands
* the operators seen (a sequence)
* the operands seen (a sequence)
'''
def aux(self, node):
'''Actual function that updates the stats.'''
results = meth(self, node)
self.operators += results[0]
self.operands += results[1]
self.operators_seen.update(results[2])
for operand in results[3]:
new_operand = getattr(operand,
self.types.get(type(operand), ''),
operand)
name = self.get_name(operand)
new_operand = getattr(operand, self.types.get(name, ""), operand)
self.operands_seen.add((self.context, new_operand))
# Now dispatch to children
super(HalsteadVisitor, self).generic_visit(node)
return aux
@dispatch
def visit_BinOp(self, node):
'''A binary operator.'''
return (1, 2, (self.get_name(node.op),), (node.left, node.right))
@dispatch
def visit_UnaryOp(self, node):
'''A unary operator.'''
return (1, 1, (self.get_name(node.op),), (node.operand,))
@dispatch
def visit_BoolOp(self, node):
'''A boolean operator.'''
return (1, len(node.values), (self.get_name(node.op),), node.values)
@dispatch
def visit_AugAssign(self, node):
'''An augmented assign (contains an operator).'''
return (1, 2, (self.get_name(node.op),), (node.target, node.value))
@dispatch
def visit_Compare(self, node):
'''A comparison.'''
return (len(node.ops), len(node.comparators) + 1,
map(self.get_name, node.ops), node.comparators + [node.left])
def visit_FunctionDef(self, node):
'''When visiting functions, another visitor is created to recursively
analyze the function's body. We also track information on the function
itself.
'''
func_visitor = HalsteadVisitor(context=node.name)
for child in node.body:
visitor = HalsteadVisitor.from_ast(child, context=node.name)
self.operators += visitor.operators
self.operands += visitor.operands
self.operators_seen.update(visitor.operators_seen)
self.operands_seen.update(visitor.operands_seen)
func_visitor.operators += visitor.operators
func_visitor.operands += visitor.operands
func_visitor.operators_seen.update(visitor.operators_seen)
func_visitor.operands_seen.update(visitor.operands_seen)
# Save the visited function visitor for later reference.
self.function_visitors.append(func_visitor)
| python |
import os
from glob import glob
from torch import Tensor
from typing import Tuple
import subprocess
import torchaudio
from abc import abstractmethod
from clmr.datasets import Dataset
import random
def preprocess_audio(source, target, sample_rate):
p = subprocess.Popen(
["ffmpeg", "-i", source, "-ac", "1", "-ar", str(sample_rate), target, "-loglevel", "quiet"]
)
p.wait()
class HUM2SONG(Dataset):
"""Create a Dataset for any folder of audio files.
Args:
root (str): Path to the directory where the dataset is found or downloaded.
src_ext_audio (str): The extension of the audio files to analyze.
"""
def __init__(
self,
root: str,
src_ext_audio: str = ".mp3",
n_classes: int = 1,
) -> None:
super(HUM2SONG, self).__init__(root)
self._path = root
self._src_ext_audio = src_ext_audio
self.n_classes = n_classes
self.hum = sorted(glob(
os.path.join(self._path, "hum", "**", "*{}".format(self._src_ext_audio)),
recursive=True,
))
self.song = sorted(glob(
os.path.join(self._path, "song", "**", "*{}".format(self._src_ext_audio)),
recursive=True,
))
n_hum = len(self.hum)
self.label = [1.0] * n_hum
for i in range(n_hum):
h = self.hum[i]
self.hum.append(h)
ran_songs = random.sample(self.song, k=10)
for s in ran_songs:
if s[s.rfind('/')+1:] != h[h.rfind('/')+1:]:
self.song.append(s)
self.label.append(0)
if len(self.hum) == 0:
raise RuntimeError(
"Dataset not found. Please place the audio files in the {} folder.".format(
self._path
)
)
def file_path(self, n: int, it: int) -> str:
if it == 0:
fp = self.hum[n]
elif it == 1:
fp = self.song[n]
return fp
def __getitem__(self, n: int) -> Tuple[Tensor, Tensor]:
"""Load the n-th sample from the dataset.
Args:
n (int): The index of the sample to be loaded
Returns:
Tuple [Tensor, Tensor]: ``(waveform, label)``
"""
hum, _ = self.load(n, 0)
song, _ = self.load(n, 1)
label = self.label[n]
return hum, song, label
def __len__(self) -> int:
return len(self.hum)
def target_file_path(self, n: int, it: int) -> str:
fp = self.file_path(n, it)
file_basename, _ = os.path.splitext(fp)
return file_basename + self._ext_audio
def preprocess(self, n: int, sample_rate: int):
for it in [0, 1]:
fp = self.file_path(n, it)
target_fp = self.target_file_path(n, it)
assert fp[fp.rfind('/'):] != target_fp[target_fp.rfind('/'):]
if not os.path.exists(target_fp):
preprocess_audio(fp, target_fp, sample_rate)
def load(self, n, it: int):
target_fp = self.target_file_path(n, it)
try:
audio, sample_rate = torchaudio.load(target_fp)
except OSError as e:
print("File not found, try running `python preprocess.py` first.\n\n", e)
return
return audio, sample_rate
| python |
# -------------------------------------------------------------
# Authors: Tim van Zalingen (10784012)
# Maico Timmerman (10542590)
# Date: 12 April 2016
# File: 21.py
#
# The file for assignment 2.1. Plots N number pairs using
# uniform.
# -------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
def ibm_rnd(N, seed):
a = 65539
c = 0
m = 2**31
numbers = [seed]
for i in range(1, N):
numbers.append((a * numbers[i - 1] + c) % float(m))
return np.array(numbers) / m
def main():
N = 100
x = ibm_rnd(N, 983)
y = ibm_rnd(N, 759)
plt.title('{0} number pairs created with IBM RND'.format(N))
plt.plot(x, y, 'o')
plt.show()
if __name__ == '__main__':
main()
| python |
#!/usr/bin/env python3
from Bio import SeqIO
import argparse
import glob, os
import sys
def GetArguments():
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--fasta_folder", type=str, required=True, help="The folder that holds the nfcongeneus outputted fasta files.")
parser.add_argument("-m", "--max_frac", type=float, required=True, help="The maximum fraction of missing data allowed to keep the sequence in the fasta file (in decimal numbers).")
parser.add_argument("-o", "--outdir", type=str, required=True, help="The diretory were filtered output should be written into. Output will be renamed and will not overwrite orginal nfcongeneues output.")
args = parser.parse_args()
return args
def CalcNfrac(seq, id):
N = seq.count("N")
n = seq.count("n")
l = len(seq)
try:
frac = (n + N) / l
except ZeroDivisionError:
sys.exit(id + " has length 0. Please have a look at this file. Exiting...")
return(frac)
def RemoveSeqs(file, maxfrac, out):
outfile = out+"/"+os.path.basename(file)[:-6]+"_"+str(maxfrac)+"_NfracRM.fasta"
out = open(outfile, "a")
for genomes in SeqIO.parse(file, 'fasta'):
id = genomes.id
seq = genomes.seq
frac = CalcNfrac(seq, id)
if frac < maxfrac:
out.write(">"+id+"_Nfrac:"+str(frac)+"\n"+str(seq)+"\n")
out.close
########################
def main():
arg = GetArguments()
for fasta in glob.glob(arg.fasta_folder+"/*.fasta"):
RemoveSeqs(fasta, arg.max_frac, arg.outdir)
if __name__=='__main__':
main()
| python |
import torch.nn as nn
import torch.nn.functional as F
import torch
import numpy as np
def load_embedding_model(pt_file, embedding_size):
"""Return an EmbeddingNet model with saved model weights, usable for inference only."""
model = EmbeddingNet(embedding_size)
# Explicitly map CUDA-trained models to CPU otherwise this will raise an error
model.load_state_dict(torch.load(pt_file, map_location=torch.device('cpu')))
model.eval()
return model
def extract_embeddings(dataloader, model):
"""Return embeddings from a model with a get_embedding method (uses CPU)."""
model = model.cpu()
with torch.no_grad():
model.eval()
embedding_size = list(model.children())[-1].out_features
embeddings = np.zeros((len(dataloader.dataset), embedding_size))
labels = np.zeros(len(dataloader.dataset))
count = 0
for input_data, target in dataloader:
embeddings[count:count+len(input_data), :] = model.get_embedding(input_data).data.cpu().numpy()
labels[count:count+len(input_data)] = target.numpy()
count += len(input_data)
return embeddings, labels
class GaitDataset(torch.utils.data.Dataset):
"""Classification-based dataset which returns individual samples.
Class signature is based on the PyTorch MNIST dataset."""
def __init__(self, dfs, train=True):
"""dfs is a list of DataFrames corresponding to chunked data."""
self._dfs = dfs
self.train = train
self.targets = torch.Tensor([df["user_id"].iloc[0] for df in dfs]).long()
self.data = torch.Tensor([
np.stack([
chunk["linearaccelerometer_mag"].values,
chunk["gyroscope_mag"].values,
])
for chunk in self._dfs
])
self.transform = None
@property
def train_labels(self):
return self.targets
@property
def test_labels(self):
return self.targets
@property
def train_data(self):
return self.data
@property
def test_data(self):
return self.data
def __getitem__(self, idx):
return self.data[idx,:,:], self.targets[idx]
def __len__(self):
return len(self._dfs)
class EmbeddingNet(nn.Module):
"""Model definition for outputting a lower-dimensional embedding."""
def __init__(self, embedding_size):
super().__init__()
self.conv1 = nn.Sequential(
nn.Conv1d(2, 16, 5, padding=2, padding_mode="replicate"), nn.ReLU(),
nn.Conv1d(16, 32, 5, padding=2, padding_mode="replicate"), nn.ReLU(),
nn.MaxPool1d(2)
)
self.conv2 = nn.Sequential(
nn.Conv1d(34, 64, 3, padding=1, padding_mode="replicate"), nn.ReLU(),
nn.Conv1d(64, 64, 3, padding=1, padding_mode="replicate"), nn.ReLU(),
nn.MaxPool1d(2),
nn.Flatten()
)
self.fc = nn.Linear(in_features=32 * 64, out_features=embedding_size)
def forward(self, x):
conv1 = self.conv1(x)
# Add FFT as intermediate channel, stack with conv1
fft = self._rfft(x)
encoder = self.conv2(torch.cat([conv1, fft], dim=1))
embedding = self.fc(encoder)
return embedding
def get_embedding(self, x):
return self.forward(x)
def _rfft(self, signal, remove_mean=True):
"""Return FFT."""
N = signal.shape[-1]
if remove_mean:
fft = torch.rfft(signal - signal.mean(), 1)
else:
fft = torch.rfft(signal, 1)
# Clip last value so that size of output is N//2 (compatible with MaxPool)
return (2/N * (fft[...,0].pow(2) + fft[...,1].pow(2)).sqrt())[...,:N//2]
class ClassificationNet(nn.Module):
"""Model definition for performing classification using embeddings."""
def __init__(self, embedding_net, n_classes):
super().__init__()
self.embedding_net = embedding_net
embedding_size = list(embedding_net.children())[-1].out_features
self.n_classes = n_classes
self.nonlinear = nn.ReLU()
self.fc1 = nn.Linear(embedding_size, n_classes)
def forward(self, x):
output = self.embedding_net(x)
output = self.nonlinear(output)
scores = F.log_softmax(self.fc1(output), dim=-1)
return scores
def get_embedding(self, x):
return self.nonlinear(self.embedding_net(x))
def train_epoch(train_loader, model, loss_criterion, optimizer, device):
"""Run a single training epoch (update weights based on loss function).
Arguments:
train_loader: training DataLoader
model: PyTorch model object
loss_criterion: loss function
optimizer: optimizer
device: device to put inputs from dataset on (should match model)
Returns:
loss: the loss at the end of the epoch
"""
model.train()
total_loss = 0 # for computing accuracy
accuracy = 0
total = 0
for i, (data, target) in enumerate(train_loader):
data = data.to(device)
target = target.to(device)
optimizer.zero_grad()
out = model(data)
loss = loss_criterion(out, target)
# compute accumulated gradients
loss.backward()
# perform parameter update based on current gradients
optimizer.step()
total_loss += loss.item()
accuracy += (out.argmax(dim=1) == target).sum().item()
total += target.size(0)
accuracy /= total
total_loss /= len(train_loader)
return loss, accuracy
def test_epoch(test_loader, model, loss_criterion, device):
"""Run a single validation epoch (run model in inference without updating weights).
Arguments:
test_loader: test DataLoader
model: PyTorch model object
loss_criterion: loss function
device: device to put inputs from dataset on (should match model)
Returns:
loss: the loss at the end of the epoch
"""
total_loss = 0 # for computing accuracy
accuracy = 0
total = 0
with torch.no_grad():
model.eval()
for i, (data, target) in enumerate(test_loader):
data = data.to(device)
target = target.to(device)
out = model(data)
loss = loss_criterion(out, target)
total_loss += loss.item()
accuracy += (out.argmax(dim=1) == target).sum().item()
total += target.size(0)
accuracy /= total
total_loss /= len(test_loader)
return loss, accuracy | python |
import utils
import glob
import os
import pandas as pd
import numpy as np
import math
import pca as p
def getbytes(dataframe, payload_length=810):
values = dataframe['bytes'].values
bytes = np.zeros((values.shape[0], payload_length))
for i, v in enumerate(values):
payload = np.zeros(payload_length, dtype=np.uint8)
payload[:v.shape[0]] = v
bytes[i] = payload
return bytes
def getmeanstd(dataframe, label):
labels = dataframe['label'] == label
bytes = getbytes(dataframe[labels])
# values = dataframe[labels]['bytes'].values
# bytes = np.zeros((values.shape[0], values[0].shape[0]))
# for i, v in enumerate(values):
# bytes[i] = v
# Ys = (X - np.mean(X, axis=0)) / np.std(X, axis=0)
mean = np.mean(bytes, axis=0)
mean_sub = np.subtract(bytes, mean)
std = mean_sub / np.std(bytes, axis=0)
return mean, mean_sub, std
def byteindextoheaderfield(number, TCP=True):
if TCP:
bytenumber = number % 54
else:
bytenumber = number % 42
if bytenumber in range(6):
return "Destination MAC"
if bytenumber in range(6, 12):
return "Source MAC"
if bytenumber in (12, 13):
return "Eth. Type"
if bytenumber == 14:
return "IP Version and header length"
if bytenumber == 15:
return "Explicit Congestion Notification"
if bytenumber in (16, 17):
return "Total Length (IP header)"
if bytenumber in (18, 19):
return "Identification (IP header)"
if bytenumber in (20, 21):
return "Fragment offset (IP header)"
if bytenumber == 22:
return "Time to live (IP header)"
if bytenumber == 23:
return "Protocol (IP header)"
if bytenumber in (24, 25):
return "Header checksum (IP header)"
if bytenumber in range(26, 30):
return "Source IP (IP header)"
if bytenumber in range(30, 34):
return "Destination IP (IP header)"
if bytenumber in (34, 35):
return "Source Port (TCP/UDP header)"
if bytenumber in (36, 37):
return "Destination Port (TCP/UDP header)"
if bytenumber in range(38, 42):
if TCP:
return "Sequence number (TCP header)"
elif bytenumber in (38, 39):
return "Length of data (UDP Header)"
else:
return "UDP Checksum (UDP Header)"
if bytenumber in range(42, 46):
return "ACK number (TCP header)"
if bytenumber == 46:
return "TCP Header length or Nonce (TCP header)"
if bytenumber == 47:
return "TCP FLAGS (CWR, ECN-ECHO, ACK, PUSH, RST, SYN, FIN) (TCP header)"
if bytenumber in (48, 49):
return "Window size (TCP header)"
if bytenumber in (50, 51):
return "Checksum (TCP header)"
if bytenumber in (52, 53):
return "Urgent Pointer (TCP header)"
| python |
import requests
import youtube_dl
from bs4 import BeautifulSoup
import json
from constants import JSON_FORMAT_KWARGS
from utils import slugify
base_url = 'https://www.youtube.com/playlist?list=PLGVZCDnMOq0qLoYpkeySVtfdbQg1A_GiB'
conf_url = 'http://pydata.org/dc2016/schedule/'
conf_base_url = 'http://pydata.org'
video_dir = 'pydata-dc-2016/videos/'
tags_url = 'http://pyvideo.org/tags.html'
tag_base_url = 'http://pyvideo.org/tag/'
tough_tags = ['with', 'building', 'python']
def get_tags():
"""Gets all tags from pyvideo"""
r = requests.get(tags_url)
soup = BeautifulSoup(r.text)
links = soup.find_all('a')
links = [link for link in links if link['href'].startswith(tag_base_url)]
return [link.text for link in links]
def get_youtube_data():
try:
with open('test.json') as f:
info_dict = json.load(f)
except:
ydl_opts = {
'dump_single_json': True,
'simulate': True
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(base_url, download=False)
with open('test.json', 'w') as f:
json.dump(info_dict, f)
return info_dict
def get_speakers(video):
"""Return list of speakers"""
if ' | ' in video['title']:
speakers = video['title'].split(' | ')[0]
return [s.strip() for s in speakers.split(',')]
elif ' - ' in video['title']:
speakers = video['title'].split(' - ')[0]
return [s.strip() for s in speakers.split(',')]
else:
return ['']
def get_title(video):
"""Return title"""
print('Trying: ' + video['title'])
if ' | ' in video['title']:
return video['title'].split(' | ')[1]
elif ' - ' in video['title']:
return video['title'].split(' - ')[1]
else:
return video['title']
def get_related_urls(video):
"""Get related urls"""
to_return = []
for word in video['description'].split():
if word.startswith('http://') or word.startswith('https://'):
if 20 < len(word) < 100:
to_return.append(word)
return to_return
def get_upload_date(video):
upload_date = video['upload_date']
return upload_date[:4] + '-' + upload_date[4:6] + '-' + upload_date[6:8]
if __name__ == '__main__':
info_dict = get_youtube_data()
conf_data = requests.get(conf_url)
soup = BeautifulSoup(conf_data.text)
hrefs = soup.find_all(['a', 'h3'])
conf_list = []
for href in hrefs:
if 'Friday Oct. 7, 2016' in href.text:
curr_date = '2016-10-07'
elif 'Saturday Oct. 8, 2016' in href.text:
curr_date = '2016-10-08'
elif 'Sunday Oct. 9, 2016' in href.text:
curr_date = '2016-10-09'
elif href.get('href') and 'presentation' in href['href']:
conf_list.append((href.text, conf_base_url + href['href'], curr_date))
all_tags = get_tags()
for video in info_dict['entries']:
this_video_tags = video['tags']
recorded = ''
title = get_title(video)
for tag in all_tags:
if tag in tough_tags:
pass
elif tag.lower() in title.lower().split():
this_video_tags.append(tag)
elif ' ' in tag and tag.lower() in title.lower():
this_video_tags.append(tag)
related_urls = get_related_urls(video)
for presentation in conf_list:
if title.lower().strip().replace('-', ' ') == presentation[0].lower().strip().replace('-', ' '):
related_urls.append(presentation[1])
recorded = presentation[2]
upload_date = video['upload_date']
video_dict = {
'description': video['description'],
'speakers': get_speakers(video),
'thumbnail_url': video['thumbnail'],
'title': title,
'recorded': recorded or get_upload_date(video),
'videos': [
{
'type': 'youtube',
'url': video['webpage_url']
}
],
'duration': video['duration'],
'copyright_text': video['license'],
'language': 'eng',
'related_urls': related_urls,
'tags': this_video_tags
}
file_name = video_dir + slugify(title) + '.json'
with open(file_name, 'w') as f:
json.dump(video_dict, f, **JSON_FORMAT_KWARGS) | python |
SUMMARY = '/summary'
ASSETS = '/assets'
ORDERBOOK = '/orderbook/{symbol}'
TRADES = '/trades/{symbol}'
SYMBOLS = '/symbols/{symbol}'
TICKERS = '/tickers/{symbol}'
| python |
"""
Created on 8 Jul 2021
@author: Bruno Beloff ([email protected])
Based-on code
https://invensense.tdk.com/download-pdf/icp-10101-datasheet/
"""
from scs_core.climate.pressure_datum import PressureDatum
# --------------------------------------------------------------------------------------------------------------------
class ICP10101Datum(PressureDatum):
"""
TDK ICP-10101 digital barometer - data interpretation
"""
# ----------------------------------------------------------------------------------------------------------------
@classmethod
def construct(cls, actual_press, temp, altitude, include_temp=True):
sl_press = cls._sl_press(actual_press, temp, altitude)
reported_temp = temp if include_temp else None
return cls(actual_press, sl_press, reported_temp)
# ----------------------------------------------------------------------------------------------------------------
def __init__(self, actual_press, sl_press, temp):
"""
Constructor
"""
super().__init__(actual_press, sl_press, temp)
# ----------------------------------------------------------------------------------------------------------------
def __str__(self, *args, **kwargs):
return "ICP10101Datum:{actual_press:%s, sl_press:%s, temp:%s}" % \
(self.actual_press, self.sl_press, self.temp)
| python |
import pandas
import datetime
dataPath = '/Users/nikki/Dev/CIWS-Data/src/Age Study/'
inputFileName = 'datalog_Snow_Hall_2017-6-6_12-52-2.csv'
df_SnowHall = pandas.read_csv(dataPath + inputFileName,
header=1, sep=',', index_col=0, parse_dates=True,
infer_datetime_format=True, low_memory=False)
outputFileName = dataPath + 'processed_' + inputFileName
date = df_SnowHall.index + datetime.timedelta(hours=1)
flowRate = df_SnowHall['FlowRate'] * 5
incrementalVolume = df_SnowHall['IncrementalVolume'] * 5
totalizedVolume = df_SnowHall['TotalizedVolume'] * 5
processed = pandas.DataFrame(
{'Date': date,
'FlowRate': flowRate,
'IncrementalVolume': incrementalVolume,
'TotalizedVolume': totalizedVolume,
})
processed.set_index('Date', inplace=True)
processed.to_csv(outputFileName, sep=',', header=True)
# processedSnowHall = {'Date': date,
# 'FlowRate': flowRate,
# 'IncrementalVolume': incrementalVolume,
# 'TotalizedVolume': totalizedVolume}
# df = pandas.DataFrame(processedSnowHall, columns=['Date', 'FlowRate', 'IncrementalVolume', 'TotalizedVolume'])
# df.set_index('Date', inplace=True)
# df.to_csv(outputFileName, sep=',')
print(processed.columns) | python |
from setuptools import setup, find_packages
with open("README.md", "r") as stream:
long_description = stream.read()
setup(
name="may",
version="1.0.0",
description="this is a FTP wrapper library, like as built in file system library.",
long_description=long_description,
long_description_content_type="text/markdown",
author="tikubonn",
author_email="https://twitter.com/tikubonn",
url="https://github.com/tikubonn/may",
license="MIT",
packages=find_packages(exclude=("test",)),
install_requires=[],
extras_require={
"test": [
"pyftpdlib",
],
},
dependency_links=[],
entry_points={},
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
'License :: OSI Approved :: MIT License',
],
test_suite='test'
)
| python |
"""Rule for launching a Scala REPL with dependencies"""
load("@bazel_skylib//lib:dicts.bzl", _dicts = "dicts")
load(
"@io_bazel_rules_scala//scala/private:common_attributes.bzl",
"common_attrs",
"implicit_deps",
"launcher_template",
"resolve_deps",
)
load("@io_bazel_rules_scala//scala/private:common_outputs.bzl", "common_outputs")
load(
"@io_bazel_rules_scala//scala/private:phases/phases.bzl",
"extras_phases",
"phase_binary_final",
"phase_common_runfiles",
"phase_declare_executable",
"phase_merge_jars",
"phase_repl_collect_jars",
"phase_repl_compile",
"phase_repl_java_wrapper",
"phase_repl_write_executable",
"phase_scalac_provider",
"phase_unused_deps_checker",
"phase_write_manifest",
"run_phases",
)
def _scala_repl_impl(ctx):
return run_phases(
ctx,
# customizable phases
[
("scalac_provider", phase_scalac_provider),
("write_manifest", phase_write_manifest),
("unused_deps_checker", phase_unused_deps_checker),
# need scala-compiler for MainGenericRunner below
("collect_jars", phase_repl_collect_jars),
("java_wrapper", phase_repl_java_wrapper),
("declare_executable", phase_declare_executable),
# no need to build an ijar for an executable
("compile", phase_repl_compile),
("merge_jars", phase_merge_jars),
("runfiles", phase_common_runfiles),
("write_executable", phase_repl_write_executable),
],
# fixed phase
("final", phase_binary_final),
).final
_scala_repl_attrs = {
"jvm_flags": attr.string_list(),
}
_scala_repl_attrs.update(launcher_template)
_scala_repl_attrs.update(implicit_deps)
_scala_repl_attrs.update(common_attrs)
_scala_repl_attrs.update(resolve_deps)
def make_scala_repl(*extras):
return rule(
attrs = _dicts.add(
_scala_repl_attrs,
extras_phases(extras),
*[extra["attrs"] for extra in extras if "attrs" in extra]
),
executable = True,
fragments = ["java"],
outputs = _dicts.add(
common_outputs,
*[extra["outputs"] for extra in extras if "outputs" in extra]
),
toolchains = ["@io_bazel_rules_scala//scala:toolchain_type"],
implementation = _scala_repl_impl,
)
scala_repl = make_scala_repl()
| python |
import coinbase
import requests
import json
import email.utils
import smtplib, smtpd
import imaplib
import asyncore
import sys
import getpass
from email.mime.text import MIMEText
import email
#Conversion of 1 bitcoin = MUR
url = "http://blockchain.info/ticker"
response = requests.get(url)
USD = (json.loads(response.text)['USD']['last'])
MUR = round((USD * 31),2) #formula for dollar to MUR
mmsg = ('1 Bitcoin = ' + str(MUR) + ' MUR')
USD = str(USD)
print (mmsg)
#print trnasaction rate.
coinbase = coinbase.Coinbase.with_api_key("dNCXFJk2cQHTBkKl", "HG8PynSQ1cvdJXwYnZUnXayylHAym8nV")
balance = coinbase.get_balance()
bmsg = ('Balance is ' + balance + ' BTC ')
print(bmsg)
# print bitcoin balance.
#total mur
tmur = round((float(balance) * int(MUR)),2)
print ('Balance is ' +str(tmur) )
# Create the message
fromaddr = '[email protected]'
toaddrs = '#[email protected]'
msg1 = (bmsg + ' ' + str(tmur) + ' MUR' + ' ' + mmsg)
server = smtplib.SMTP("smtp.gmail.com:587")
server.starttls()
username = '[email protected]'
password = 'password'
server.login(username,password)
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('[email protected]', 'password')
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.
result, data = mail.uid('search', None, "ALL") # search and return uids instead
latest_email_uid = data[0].split()[-1]
result, data = mail.uid('fetch', latest_email_uid, '(RFC822)')
raw_email = data[0][1]
rv, mailboxes = mail.list()
if rv == 'OK':
print ("Mailboxes:")
print (mailboxes)
def process_mailbox(mail):
"""
Do something with emails messages in the folder.
For the sake of this example, print some headers.
"""
rv, data = mail.search(None, "ALL")
if rv != 'OK':
print ("No messages found!")
return
for num in data[0].split():
rv, data = mail.fetch(num, '(RFC822)')
if rv != 'OK':
print ("ERROR getting message", num)
return
msg = (data[0][1])
msg = msg.decode(encoding='UTF-8')
msg = email.message_from_string(msg)
decode = email.header.decode_header(msg['From'])[0]
msg = (decode[0])
if (msg == '[email protected]'):
server.sendmail('[email protected]', '[email protected]', msg1)
server.quit()
process_mailbox(mail) # ... do something with emails, see below ...
mail.close()
mail.logout()
| python |
# for comeplte calibratio, in this we will consider base(B), camera(C), gripper(G) and AR Tag(A) frames
# trasform from B<-->G and C<-->A is known
# need to figure out transform between G<-->A and B<-->C
# P_X_Y --> represent origin of Y frame in X frame of reference
import torch
from torch import optim
import numpy as np
from mpl_toolkits import mplot3d
import matplotlib.pyplot as plt
import matplotlib
from util import quat2mat, quat2rot, compute_loss
import argparse
import os
import pickle
import random
class GetCameraExtrensics(object):
def __init__(self, args):
"""
:param args:
"""
self.data_dir = args.data_dir
self.rot_loss_w = args.rot_loss_w
self.vis = args.vis
self.num_iter = args.num_iter
self.base_frame = args.base_frame
self.camera_frame = args.camera_frame
self.num_train_points = args.num_data_points
self.num_ransac_iter = args.num_ransac_iter
self.inlier_thr = args.inlier_thr
def calibrate(self):
"""
:return:
"""
# generate data
self.load_data(self.data_dir)
# optimize the parmas
self.optimize_ransac(self.num_iter, self.rot_loss_w, self.num_ransac_iter, self.inlier_thr, self.vis)
# data set generator
def load_data(self, data_dir):
"""
:param data_dir:
:return:
"""
# load hand data
with open(os.path.join(data_dir, 'arm_2.p'), 'rb') as f:
try:
arm_data = pickle.load(f)['data']
except:
arm_data = pickle.load(f, encoding='latin1')['data']
# load marker data
with open(os.path.join(data_dir, 'marker_2.p'), 'rb') as f:
try:
marker_data = pickle.load(f)['data']
except:
marker_data = pickle.load(f, encoding='latin1')['data']
self.num_points = min(len(arm_data),len(marker_data))
self.trans_B_G = torch.from_numpy(np.array([arm_data[i]['position'] for i in range(self.num_points)])
.reshape(-1, 3))
self.rot_B_G = torch.from_numpy(np.array([arm_data[i]['orientation'] for i in range(self.num_points)]))
self.trans_C_A = torch.from_numpy(np.array([marker_data[i]['position'] for i in range(self.num_points)]).
reshape(-1, 3))
quat_C_A = torch.from_numpy(np.array([marker_data[i]['orientation'] for i in range(self.num_points)]))
self.rot_C_A = quat2rot(quat_C_A, format='xyzw')
self.num_points = self.trans_B_G.shape[0]
# optimize the parameters
def optimize_ransac(self, num_iter, rot_loss_w, num_ransac_iter, inlier_thr, vis):
"""
:param num_iter:
:param rot_loss_w:
:param num_ransac_iter:
:param inlier_thr:
:param vis:
:return:
"""
max_inliers = None
for n in range(num_ransac_iter):
# sample random num_points from data to optimize paramters
print("\n training with {} data points".format(self.num_train_points))
train_indx = random.sample(range(self.num_points), self.num_train_points)
train_trans_B_G = torch.stack([self.trans_B_G[i] for i in train_indx], dim=0)
train_rot_B_G = torch.stack([self.rot_B_G[i] for i in train_indx], dim=0)
train_trans_C_A = torch.stack([self.trans_C_A[i] for i in train_indx], dim=0)
train_rot_C_A = torch.stack([self.rot_C_A[i] for i in train_indx], dim=0)
test_trans_B_G = torch.stack([self.trans_B_G[i] for i in range(self.num_points) if i not in train_indx],
dim=0)
test_rot_B_G = torch.stack([self.rot_B_G[i] for i in range(self.num_points) if i not in train_indx], dim=0)
test_trans_C_A = torch.stack([self.trans_C_A[i] for i in range(self.num_points) if i not in train_indx],
dim=0)
test_rot_C_A = torch.stack([self.rot_C_A[i] for i in range(self.num_points) if i not in train_indx], dim=0)
# start with some random guess
quat_B_C = torch.rand(1,3).double().requires_grad_(True)
trans_B_C = torch.rand(1,3).double().requires_grad_(True)
quat_G_A = torch.rand(1,3).double().requires_grad_(True)
trans_G_A = torch.rand(1,3).double().requires_grad_(True)
optimizer = optim.Adam([quat_B_C, trans_B_C, trans_G_A, quat_G_A], lr=0.1)
criterion = torch.nn.MSELoss(reduction='none')
best_train_loss, best_train_quat_B_C, best_train_trans_B_C, best_train_quat_G_A, best_train_trans_G_A = \
None, None, None, None, None
###################
# optimize on the train set the B<-->C & G<-->A
for it in range(num_iter):
_, train_loss = compute_loss(train_trans_B_G, train_rot_B_G, train_trans_C_A, train_rot_C_A, trans_G_A,
quat_G_A, trans_B_C, quat_B_C, criterion, rot_loss_w)
optimizer.zero_grad()
train_loss.backward()
optimizer.step()
if best_train_loss is None or train_loss.item() < best_train_loss:
best_train_loss = train_loss.item()
best_train_quat_B_C = quat_B_C.detach().numpy()
best_train_trans_B_C = trans_B_C.detach().numpy()
best_train_quat_G_A = quat_G_A.detach().numpy()
best_train_trans_G_A = trans_G_A.detach().numpy()
if it % 100 == 0:
print("train_loss = {:05f}".format(train_loss.item()))
###################
# find inliers
with torch.no_grad():
test_loss, _ = compute_loss(test_trans_B_G, test_rot_B_G, test_trans_C_A, test_rot_C_A,
torch.from_numpy(best_train_trans_G_A),
torch.from_numpy(best_train_quat_G_A),
torch.from_numpy(best_train_trans_B_C),
torch.from_numpy(best_train_quat_B_C), criterion, rot_loss_w)
# include all inliers in train set
num_inliers = 0
for indx, l in enumerate(test_loss):
if l.item() < inlier_thr:
train_trans_B_G = torch.cat((train_trans_B_G, test_trans_B_G[indx].unsqueeze_(0)), dim=0)
train_rot_B_G = torch.cat((train_rot_B_G, test_rot_B_G[indx].unsqueeze_(0)), dim=0)
train_trans_C_A = torch.cat((train_trans_C_A, test_trans_C_A[indx].unsqueeze_(0)), dim=0)
train_rot_C_A = torch.cat((train_rot_C_A, test_rot_C_A[indx].unsqueeze_(0)), dim=0)
num_inliers += 1
print("num_inliers = {}".format(num_inliers))
# fine tune the params
if num_inliers == 0:
continue
if max_inliers is None or num_inliers > max_inliers:
max_inliers = num_inliers
print("training with {} data points".format(train_trans_B_G.shape[0]))
# train again
best_loss, best_quat_B_C, best_trans_B_C, best_quat_G_A, best_trans_G_A = None, None, None, None, None
for it in range(num_iter):
# optimize paramters
optimizer.zero_grad()
_, train_loss = compute_loss(train_trans_B_G, train_rot_B_G, train_trans_C_A, train_rot_C_A,
trans_G_A,
quat_G_A, trans_B_C, quat_B_C, criterion, rot_loss_w)
if best_loss is None or train_loss.item() < best_loss:
best_loss = train_loss.item()
best_quat_B_C = quat_B_C.detach().numpy()
best_trans_B_C = trans_B_C[0].detach().numpy()
best_trans_G_A = trans_G_A[0].detach().numpy()
train_loss.backward()
optimizer.step()
if it % 100 == 0:
print("train_loss = {:05f}".format(train_loss.item()))
best_rot_B_C, best_quat_B_C = quat2mat(torch.from_numpy(best_quat_B_C))
best_rot_B_C, best_quat_B_C = best_rot_B_C[0].detach().numpy(), best_quat_B_C[0].detach().numpy()
print("\n for B<-->C ")
cmd = "rosrun tf static_transform_publisher " + str(float(best_trans_B_C[0])) + ' ' + \
str(float(best_trans_B_C[1])) + ' ' + str(float(best_trans_B_C[2])) + ' ' + str(best_quat_B_C[1]) + ' ' \
+ str(best_quat_B_C[2]) + ' ' + str(best_quat_B_C[3]) + ' ' + str(best_quat_B_C[0]) + ' ' + \
self.base_frame + ' '+ self.camera_frame + ' 10'
print("Run Command")
print(cmd)
# plot the points for visualization
if vis:
trans_B_G_A = self.trans_B_G.numpy().reshape(-1,3) + np.array([np.matmul(self.rot_B_G[i].numpy(),
best_trans_G_A.reshape(-1,3).T).T
for i in range(self.num_points)]).reshape(-1,3)
trans_B_C_A = np.matmul(best_rot_B_C,self.trans_C_A.numpy().reshape(-1,3).T).T + best_trans_B_C.reshape(-1,3)
ax = plt.axes(projection='3d')
ax.scatter3D(trans_B_G_A[:,0], trans_B_G_A[:,1], trans_B_G_A[:,2])
ax.scatter3D(trans_B_C_A[:,0], trans_B_C_A[:,1], trans_B_C_A[:,2], color='red')
scatter1_proxy = matplotlib.lines.Line2D([0],[0], linestyle="none", marker = 'o')
scatter2_proxy = matplotlib.lines.Line2D([0],[0], linestyle="none", c='red', marker = 'o')
ax.legend([scatter1_proxy, scatter2_proxy], ['Base to Ar from Gripper', 'Base to Ar from Camera'], numpoints = 1)
plt.show()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Process args for calibration")
parser.add_argument('--rot_loss_w', help='weight on rotational loss for optimizing the camera extrensic parameters', type=float, default=0.0)
parser.add_argument('--vis', action='store_true', default=False, help='for visualizing data pooints after calibration')
parser.add_argument('--num_iter', help='number of iteration of optimization', type=int, default=1000)
parser.add_argument('--data_dir', help='Directory to load data points', type=str, default="robot_ar_data")
parser.add_argument('--base_frame', help='robot base frame name', type=str, default="/base")
parser.add_argument('--camera_frame', help='camera frame name', type=str, default="/kinect2_rgb_optical_frame")
parser.add_argument('--num_data_points', help='number of data points used to optimize the intial guess', type=int, default=5)
parser.add_argument('--num_ransac_iter', help='number of data points used to optimize the intial guess', type=int,
default=20)
parser.add_argument('--inlier_thr', help='the loss below which the point will be considered inlier', type=float,
default=0.01)
args = parser.parse_args()
get_camera_extrensics = GetCameraExtrensics(args)
get_camera_extrensics.calibrate() | python |
import os
import json
import logging
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from . import bot
HUB_VERIFY_TOKEN = os.environ.get('WAHLTRAUD_HUB_VERIFY_TOKEN', 'na')
logger = logging.getLogger(__name__)
@csrf_exempt
def webhook(request):
if request.method == 'GET':
if request.GET.get('hub.verify_token') == HUB_VERIFY_TOKEN:
return HttpResponse(request.GET['hub.challenge'], content_type="text/plain")
else:
return HttpResponse('Hello World!', content_type="text/plain")
elif request.method == 'POST':
data = json.loads(request.body.decode())
try:
logger.debug('handling events')
bot.handle_events(data)
except:
logger.exception("Error handling messages")
return HttpResponse("ok", content_type="text/plain")
| python |
import pytest
@pytest.fixture(params=[True, False])
def opt_einsum(request, monkeypatch):
if not request.param:
monkeypatch.delattr("opt_einsum.contract")
@pytest.fixture(params=[1, 2])
def channels(request):
return request.param
| python |
# Copyright 2021 Universität Tübingen, DKFZ and EMBL for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from . import models
def setup(env):
request = env['request']
# start a transaction
request.tm.begin()
# inject some vars into the shell builtins
env['tm'] = request.tm
env['dbsession'] = request.dbsession
env['models'] = models
| python |
import json, os, time
import openshift as oc
from subprocess import check_output
def env_set(env_var, default):
if env_var in os.environ:
return os.environ[env_var]
elif os.path.exists(env_var) and os.path.getsize(env_var) > 0:
with open(env_var, 'r') as env_file:
var = env_file.read().strip()
env_file.close()
return var
else:
return default
def main():
org = env_set('PIPELINE_MANIFEST_MIRROR_ORG', 'acm-d')
mirror_tag = env_set('PIPELINE_MANIFEST_MIRROR_TAG', 'multicluster-engine-1.0-rhel-8-container-candidate')
max_retries = 5
results = list_tags(mirror_tag)
results = results.decode('utf8').replace("'", '"')
images = json.loads(results)
for index, image_data in enumerate(images):
image_done = False
retries = 0
while image_done == False:
try:
if (retries == 0):
retry_phrase = ""
else:
retry_phrase = "(retry {} of {})".format(retries, max_retries)
nvr = image_data['nvr']
results2 = brew_build_info(nvr).decode('utf8').replace("'", '"')
build = json.loads(results2)
pullspec = build['extra']['image']['index']['pull'][0]
nicespec = build['extra']['image']['index']['pull'][1].replace(
'registry-proxy.engineering.redhat.com/rh-osbs/multicluster-engine-', ''
)
print('Initiating mirror of {} to {}, image {} of {} {}'.format(pullspec,nicespec,index+1,len(images),retry_phrase))
oc.invoke(
'image',
cmd_args=[
'mirror',
'--keep-manifest-list=true',
'--filter-by-os=.*',
'{0}'.format(pullspec),
'quay.io/{0}/{1}'.format(org, nicespec)
]
)
image_done = True
except oc.OpenShiftPythonException as error:
print('Unable to mirror image {}'.format(nicespec))
try:
# Try to pluck out just the exact thing that went wrong
error_info = json.loads(str(error).strip("[Non-zero return code from invoke action]"))
print('{}'.format(error_info['actions'][0]['err']))
except:
# If things go really awry, just print out the whole thing
print('error: {}'.format(str(error)))
retries += 1
if (retries < max_retries):
delay = 10 * retries
print("Sleeping for {} seconds before retrying...".format(delay))
time.sleep(delay)
else:
print('Maximum retries reached for image; continuing')
image_done = True
def list_tags(tag):
return check_output(
[
"brew",
"call",
"listTagged",
tag,
"--json-output",
"None",
"True",
"None",
"True"
]
)
def brew_build_info(nvr):
return check_output(
[
'brew',
'call',
'getBuild',
nvr,
'--json-output'
]
)
if __name__ == '__main__':
main()
| python |
"""
A module with internal/private models that are not thought to be used outside the MAUS package itself.
"""
from typing import Callable, List, Optional
from xml.etree.ElementTree import Element
import attrs
from lxml import etree # type:ignore[import]
from maus.models.edifact_components import EdifactStack, EdifactStackQuery
# pylint:disable=too-few-public-methods
@attrs.define(auto_attribs=True, kw_only=True)
class MigFilterResult:
"""
the (internal) result of a query path search inside the tree
"""
is_unique: Optional[bool] #: True iff unique, None for no results, False for >1 result
unique_result: Optional[Element] #: unique element if there is any; None otherwise
candidates: Optional[List[Element]] #: list of candidates if there is >1 result
# pylint:disable=too-few-public-methods
@attrs.define(auto_attribs=True, kw_only=True)
class EdifactStackSearchStrategy:
"""
The search strategy allows to have a compact yet descriptive representation on how the edifact stack search works.
The alternative to this is a very nested and hard to understand if/else/then structure with lots of branches.
Any step inside the strategy has three possible outcomes which are represented by the :class:`_XQueryPathResult`:
1. There is exactly one unique result => return/exit
2. There are no results => start over again
3. There are >1 results => apply additional filters
"""
#: name, e.g. "filter by data element id"
name: str = attrs.field(validator=attrs.validators.instance_of(str))
#: the filter is the function that describes the strategy. It consumes the query and (optionally) a list of elements
filter: Callable[[EdifactStackQuery, Optional[List[Element]]], MigFilterResult] = attrs.field(
validator=attrs.validators.is_callable()
)
#: The unique result strategy is to return an edifact stack for the unique result element
unique_result_strategy: Callable[[Element], EdifactStack] = attrs.field(validator=attrs.validators.is_callable())
#: the no result strategy is to apply another filter based on those candidates that lead to no result (fallback)
no_result_strategy: Optional["EdifactStackSearchStrategy"]
#: in case of multiple results the next strategy uses the multiple results as input (sharpen)
multiple_results_strategy: Optional["EdifactStackSearchStrategy"]
def apply(self, query: EdifactStackQuery, pre_selection: Optional[List[Element]] = None) -> Optional[EdifactStack]:
"""
Apply the defined strategy until we either have no ideas left or a unique result is found
"""
# https://stackoverflow.com/questions/47972143/using-attr-with-pylint
# pylint: disable=not-callable
filter_result: MigFilterResult = self.filter(query, pre_selection)
if filter_result.is_unique is True:
return self.unique_result_strategy(filter_result.unique_result) # type:ignore[arg-type]
if filter_result.candidates and len(filter_result.candidates) > 1:
if self.multiple_results_strategy is not None:
return self.multiple_results_strategy.apply(query, filter_result.candidates)
return None
if self.no_result_strategy is not None:
return self.no_result_strategy.apply(query, pre_selection)
return None
| python |
# Dash packages
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
# Graphing packages
import plotly.graph_objs as go
import plotly.express as px
from mapboxgl.utils import *
from mapboxgl.viz import *
# Other packages
import numpy as np
import pandas as pd
from statistics import *
from data_cleaning import script, maindataclean
external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
df = maindataclean.clean_data()
df = df.dropna()
all_options = {
"Education Level": [
"Less Than Primary School",
"Completed Primary School",
"Completed College",
"Completed High School",
"Some High School",
"Some College",
],
"Water Access": [
"2-3x A Week",
"4-6x A Week",
"1x A Month",
"Never",
"1x A Week",
"Every day",
],
"Clinic Access": ["Yes", "No"],
"Floor Condition": ["Great", "Needs Repair", "Adequate"],
"Roof Condition": ["Adequate", "Needs Repair"],
"Latrine or Bathroom Access": ["Yes", "No"],
}
app.layout = html.Div(
[
html.Div(
[
dcc.Graph(
id="display-selected-values",
figure={},
style={
"top": "0",
"left": "0",
"position": "fixed",
"width": "75%",
},
)
],
style={"width": "100%", "display": "table", "top": "0", "left": "0"},
),
html.Div(
[
html.Div(
[
html.Label(
[
"City",
dcc.Dropdown(
id="city-selection",
options=[
{"label": x.capitalize(), "value": x}
for x in sorted(df["City (Clean)"].unique())
],
value="Constanza",
),
]
)
],
style={"width": "100%"},
),
html.Div(
[
html.Label(
[
"Health Feature",
dcc.Dropdown(
id="features-dropdown",
options=[
{"label": k, "value": k}
for k in all_options.keys()
],
value="Education Level",
style={"font-family": "Roboto"},
),
]
)
],
style={"width": "100%"},
),
html.Hr(),
html.Div(
[
html.Label(
[
"Multiselect Feature Status",
dcc.Dropdown(
id="options-dropdown",
multi=True,
# font_family=('Roboto',sans-serif),
# style={'size':'20%'},
value=[
"Less Than Primary School",
"Completed Primary School",
"Completed College",
"Completed High School",
"Some High School",
"Some College",
],
),
]
)
],
style={"width": "100%"},
),
html.Hr(),
],
style={
"width": "25%",
"position": "fixed",
"top": "1",
"right": "0",
"display": "table",
},
),
],
style={"top": "1", "left": "0"},
)
@app.callback(
Output("options-dropdown", "options"), Input("features-dropdown", "value")
)
def set_cities_options(selected_feature):
dff = df
dff = dff[dff[selected_feature] != ""]
return [{"label": i, "value": i} for i in all_options[selected_feature]]
@app.callback(Output("options-dropdown", "value"), Input("options-dropdown", "options"))
def set_options_value(available_options):
return [available_options[i]["value"] for i in range(len(available_options))]
@app.callback(
Output("display-selected-values", "figure"),
Input("features-dropdown", "value"),
Input("options-dropdown", "value"),
Input("city-selection", "value"),
)
def set_display_children(selected_feature, selected_option, selected_city):
token = os.getenv(
"pk.eyJ1IjoibXN1YXJlejkiLCJhIjoiY2ttZ3F1cjZ0MDAxMjJubW5tN2RsYzI2bCJ9.l7Ht-cO4Owt7vgiAY3lwsQ"
)
px.set_mapbox_access_token(
"pk.eyJ1IjoibXN1YXJlejkiLCJhIjoiY2ttZ3F1cjZ0MDAxMjJubW5tN2RsYzI2bCJ9.l7Ht-cO4Owt7vgiAY3lwsQ"
)
if selected_option == []:
dff = df[df["City (Clean)"] == selected_city]
avg_lat = mean(dff["Latitude"])
avg_lon = mean(dff["Longitude"])
fig = px.scatter_mapbox(
data_frame=dff, # [df['Clinic Access']==value],
lat=dff["Latitude"],
lon=dff["Longitude"],
zoom=13,
hover_data={"Latitude": False, "Longitude": False},
)
fig.update_traces(marker_opacity=0)
else:
dff = df[df[selected_feature].isin(selected_option)]
dff = dff[dff["City (Clean)"] == selected_city]
avg_lat = mean(dff["Latitude"])
avg_lon = mean(dff["Longitude"])
# dff = df[df['Roof Condition'].isin(value)]
fig = px.scatter_mapbox(
data_frame=dff, # [df['Clinic Access']==value],
lat=dff["Latitude"],
lon=dff["Longitude"],
color=dff[selected_feature],
# color_discrete_map={'Y':'green','N':'red','':'gray'},
hover_name="Community (Clean)",
hover_data={"Latitude": False, "Longitude": False},
zoom=13,
)
fig.update_layout(
autosize=True,
# margins=dict{l:0},
title="Dominican Republic Health Data by Household<br>(Hover over map for details)",
title_font_family="Roboto",
geo_scope="world",
geo=dict(
projection_scale=1000000, # this is kind of like zoom
center=dict(lat=avg_lat, lon=avg_lon),
), # this will center on the point
)
fig.update_traces(hoverinfo="lon")
fig.update_layout(mapbox_style="mapbox://styles/msuarez9/ckmp4rt7e0qf517o1md18w9d1")
fig.update_layout(
legend=dict(
font_family="Roboto",
orientation="h",
yanchor="bottom",
xanchor="left",
y=-0.15,
# width = '90%'
# x=0
),
hoverlabel=dict(bgcolor="white", font_size=16, font_family="Roboto"),
)
return fig
if __name__ == "__main__":
app.run_server(debug=True)
| python |
'''
Warehouse - a library of segments
===================================
A warehouse manages a library of fashion segments. Their is a local warehouse
for each fashion project under the ./fashion/warehouse directory in the
project, created by 'fashion init'.
There is also a shared global warehouse located where fashion is installed.
Each fashion project has access to all segments in its local warehouse and the
shared global warehouse.
Each segment is stored in a named subdirectory under the warehouse directory.
Each directory is named for the segment within.
A warehouse doesn't store anything about segments, so segment directories may
be deleted or copied freely, instead of using the command line functions.
/fashion/warehouse/* - segment directories
/fashion/warehouse/local - the default local segment
See the section on Segment for the directory layout under each segment
directory.
Created on 2018-12-28 Copyright (c) 2018 Bradford Dillman
'''
import copy
import logging
import os
import shutil
import zipfile
from pathlib import Path
from genson import SchemaBuilder
from munch import munchify
from tinydb import Query
from fashion.segment import Segment
from fashion.util import cd
from fashion.xforms import matchTags
class Warehouse(object):
'''Manage collection of segments.'''
def __init__(self, dir, fallback=None):
'''
Constructor.
:param Path dir: directory for segment subdirectories.
:param Warehouse fallback: another Warehouse to check for missing segments.
'''
# Location of this Warehouse.
self.dir = dir.absolute()
# Another Warehouse 2nd in priority to this one.
self.fallback = fallback
# A cache of already loaded segments.
self.segmentCache = {}
def listSegments(self):
'''
List names of segments in this warehouse.
:returns: a list of segment names in this warehouse.
:rtype: list(string)
'''
# Return the named subdirectories.
with cd(self.dir):
return [d.name for d in self.dir.iterdir() if d.is_dir()]
def loadSegment(self, segname, db, cache=None):
'''
Load a segment by name from this or fallback Warehouse.
:param string segname: name of the segment to load.
:returns: the loaded segment or None.
:rtype: Segment
'''
if cache is None:
cache = self.segmentCache
# Try the cache first.
if segname in cache:
return cache[segname]
# Next check a named subdirectory.
segfn = self.dir / segname / "segment.json"
seg = None
if segfn.exists():
if db.isVerbose():
print("Loading segment {0}".format(segname))
seg = Segment.load(segfn)
elif self.fallback is not None:
# Try the fallback Warehouse if not found.
seg = self.fallback.loadSegment(segname, db)
# Update the cache.
cache[segname] = seg
Q = Query()
# Make a note in the database.
db.table('fashion.prime.segment').upsert(seg.properties, Q.name == segname)
return seg
def loadSegments(self, db):
'''
Load all segments in this and referenced warehouses.
:returns: list of all Segment objects.
:rtype: list(Segment)
'''
db.table('fashion.prime.segment').purge()
return self.loadSegs(db, self.segmentCache)
def loadSegs(self, db, cache):
# Load all the segments in this Warehouse.
self.segments = [self.loadSegment(segname, db)
for segname in self.listSegments()]
if self.fallback is not None:
# Append the fallback Warehouse segments.
self.segments.extend(self.fallback.loadSegs(db, cache))
return self.segments
def newSegment(self, segname, db):
'''
Create a new segment in this warehouse.
:param string segname: name of the new segment.
:returns: the new Segment object.
:rtype: Segment
'''
if segname in self.listSegments():
logging.error("segment {0} already exists".format(segname))
return
segdir = self.dir / segname
segdir.mkdir(parents=True, exist_ok=True)
Segment.create(segdir, segname)
self.loadSegment(segname, db)
def exportSegment(self, segname, db):
'''
Export a segment to a zip file.
:param string segname: name of segment to export.
'''
seg = self.loadSegment(segname, db)
exportName = segname + "_v" + seg.properties.version + ".zip"
dirName = seg.absDirname.parent.resolve()
with zipfile.ZipFile(exportName, mode='w') as zip:
with cd(dirName):
for root, _, files in os.walk(segname):
if os.path.basename(root) != '__pycache__':
for file in files:
zip.write(os.path.join(root, file))
def importSegment(self, zipfilename):
'''
Import a segment from a zip file.
:param string zipfilename: filename of export.
'''
with zipfile.ZipFile(zipfilename, mode='r') as zip:
with cd(self.dir):
zip.extractall()
def deleteSegment(self, segment):
'''
Delete a segment from this warehouse.
:param Segment segment: the segment object to delete from this warehouse.
'''
shutil.rmtree(str(segment.absDirname))
def getModuleDefinitions(self, dba, tags=None):
'''
Load all "xformModules" xform module defintions from all segments
which match tags. Does NOT load the modules.
:param list(string) tags: list of tags to match before loading.
:returns: a dictionary of module definions.
:rtype: dictionary {moduleName:module}
'''
modDefs = {}
dba.table('fashion.prime.module.definition').purge()
for seg in self.segments:
xformModules = munchify(seg.findModuleDefinitions())
for m in xformModules:
if m.moduleName in modDefs:
logging.error(
"xform module name collision: {0}".format(m.moduleName))
else:
mod = munchify(m)
if "templatePath" not in mod:
if "templatePath" in seg.properties:
mod.templatePath = seg.properties.templatePath
else:
mod.templatePath = []
mod.absDirname = seg.absDirname.as_posix()
mod.moduleRootName = m.moduleName
mod.segmentName = seg.properties.name
dba.table('fashion.prime.module.definition').insert(mod)
modDefs[mod.moduleName] = mod
return modDefs
def getModuleConfigs(self, dba, moduleDict):
'''
Load all "xformConfig" xform module configurations from all segments
for modules in moduleDict. Does NOT load the modules or initialize them.
:param moduleDict: a dictionary of module definitions.
:returns: a list of xform modules configurations.
:rtype: list(xform module configs)
'''
cfgs = []
dba.table('fashion.prime.module.config').purge()
for seg in self.segments:
for c in seg.properties.xformConfig:
if c.moduleName in moduleDict:
cfg = munchify(c)
cfg.name = cfg.moduleName
cfg.segmentName = seg.properties.name
cfg.absDirname = seg.absDirname.as_posix()
# set defaults for omitted properties
if "inputKinds" not in cfg:
cfg.inputKinds = []
if "outputKinds" not in cfg:
cfg.outputKinds = []
if "tags" not in cfg:
cfg.tags = []
if "templatePath" not in cfg:
if "templatePath" in seg.properties:
cfg.templatePath = seg.properties.templatePath
else:
cfg.templatePath = []
cfgs.append(cfg)
dba.table('fashion.prime.module.config').insert(cfg)
else:
logging.error("No module for config: {0}".format(c.moduleName))
return cfgs
def getUndefinedModuleConfigs(self, moduleDict):
'''
Load all "xformConfig" from all segments for modules NOT in moduleDict.
:param moduleDict: a dictionary with keys of module names.
:returns: a list of xform modules configurations.
:rtype: list(xform module configs)
'''
cfgs = []
for seg in self.segments:
for cfg in seg.properties.xformConfig:
if cfg.moduleName not in moduleDict:
cfg.properties.name = cfg.properties.moduleName
cfgs.append(cfg)
return cfgs
def getSchemaDefintions(self):
'''
Load all segment schemas.
:returns: a dictionary of schemas for models by kind.
:rtype: dictionary {string kind:string schema filename}
'''
schemaDescrs = {}
for seg in self.segments:
for sch in seg.properties.schema:
if sch.kind in schemaDescrs:
logging.error(
"duplicate schema definition: {0}".format(sch.kind))
else:
sch.absDirname = seg.absDirname
schemaDescrs[sch.kind] = sch
return schemaDescrs
def guessSchema(self, dba, kind, existingSchema=None):
'''
Guess a JSONSchema for a model kind from examples.
:param DatabaseAccess dba: the fasion database to search.
:param string kind: the model kind to guess.
:param JSONobject existingSchema: starting schema, if any.
:returns: True if the schema was guessed and created.
:rtype: boolean
'''
objs = dba.table(kind).all()
builder = SchemaBuilder()
if existingSchema is not None:
builder.add_schema(existingSchema)
elif len(objs) == 0:
logging.error(
"Can't guess with no schema and no examples of kind {0}".format(kind))
return False
for o in objs:
builder.add_object(o)
schema = builder.to_schema()
localSeg = self.loadSegment("local", dba)
localSeg.createSchema(kind, schema)
return True
| python |
# =============================================================================
# IMPORTS
# =============================================================================
import torch
import pinot
import abc
import math
import numpy as np
# =============================================================================
# MODULE CLASSES
# =============================================================================
class BiophysicalRegressor(torch.nn.Module):
r""" Biophysically inspired model
Parameters
----------
log_sigma : `float`
..math:: \log\sigma observation noise
base_regressor : a regressor object that generates a latent F
"""
def __init__(self, base_regressor=None, *args, **kwargs):
super(BiophysicalRegressor, self).__init__()
self.base_regressor = base_regressor
self.log_sigma_measurement = torch.nn.Parameter(torch.zeros(1))
def g(self, func_value=None, test_ligand_concentration=1e-3):
return 1 / (1 + torch.exp(-func_value) / test_ligand_concentration)
def condition(
self, h=None, test_ligand_concentration=1e-3, *args, **kwargs
):
distribution_base_regressor = self.base_regressor.condition(
h, *args, **kwargs
)
# we sample from the latent f to push things through the likelihood
# Note: if we do this,
# in order to get good estimates of LLK
# we may need to draw multiple samples
f_sample = distribution_base_regressor.rsample()
mu_m = self.g(
func_value=f_sample,
test_ligand_concentration=test_ligand_concentration,
)
sigma_m = torch.exp(self.log_sigma_measurement)
distribution_measurement = torch.distributions.normal.Normal(
loc=mu_m, scale=sigma_m
)
# import pdb; pdb.set_trace()
return distribution_measurement
def loss(
self, h=None, y=None, test_ligand_concentration=None, *args, **kwargs
):
# import pdb; pdb.set_trace()
distribution_measurement = self.condition(
h=h,
test_ligand_concentration=test_ligand_concentration,
*args,
**kwargs
)
loss_measurement = -distribution_measurement.log_prob(y).sum()
# import pdb; pdb.set_trace()
return loss_measurement
def marginal_sample(
self, h=None, n_samples=100, test_ligand_concentration=1e-3, **kwargs
):
distribution_base_regressor = self.base_regressor.condition(
h, **kwargs
)
samples_measurement = []
for ns in range(n_samples):
f_sample = distribution_base_regressor.rsample()
mu_m = self.g(
func_value=f_sample,
test_ligand_concentration=test_ligand_concentration,
)
sigma_m = torch.exp(self.log_sigma_measurement)
distribution_measurement = torch.distributions.normal.Normal(
loc=mu_m, scale=sigma_m
)
samples_measurement.append(distribution_measurement.sample())
return samples_measurement
def marginal_loss(
self,
h=None,
y=None,
test_ligand_concentration=1e-3,
n_samples=10,
**kwargs
):
"""
sample n_samples often from loss in order to get a better approximation
"""
distribution_base_regressor = self.base_regressor.condition(
h, **kwargs
)
marginal_loss_measurement = 0
for ns in range(n_samples):
f_sample = distribution_base_regressor.rsample()
mu_m = self.g(
func_value=f_sample,
test_ligand_concentration=test_ligand_concentration,
)
sigma_m = torch.exp(self.log_sigma_measurement)
distribution_measurement = torch.distributions.normal.Normal(
loc=mu_m, scale=sigma_m
)
marginal_loss_measurement += -distribution_measurement.log_prob(y)
marginal_loss_measurement /= n_samples
return marginal_loss_measurement
| python |
"""
Hello World
=========================
"""
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph.console
from layer_viewer import dcolors
from layer_viewer import LayerViewerWidget
from layer_viewer.layers import *
import numpy
import skimage.data
app = pg.mkQApp()
image = skimage.data.astronaut().swapaxes(0,1)
viewer = LayerViewerWidget()
viewer.setWindowTitle('LayerViewer')
viewer.show()
layer = MultiChannelImageLayer(name='img', data=image[...])
viewer.addLayer(layer=layer)
labels = numpy.zeros(image.shape[0:2], dtype='uint8')
label_layer = LabelLayer(name='labels', data=None)
viewer.addLayer(layer=label_layer)
viewer.setData('labels',image=labels)
# connect stuff
def foo(layer):
print(labels)
label_layer.labelsChangedSignal.connect(foo)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
| python |
# proxy module
from __future__ import absolute_import
from enable.tools.base_zoom_tool import *
| python |
#
# derl: CLI Utility for searching for dead URLs <https://github.com/tpiekarski/derl>
# ---
# Copyright 2020 Thomas Piekarski <[email protected]>
#
from io import StringIO
from unittest import TestCase
from unittest.mock import patch
from pytest import raises
from conftest import (_TEST_DIRECTORY, _TEST_REQUEST_RETRIES,
_TEST_REQUESTS_TIMEOUT)
from derl.checker import _INVALID_DIRECTORY, _INVALID_RETRY, _INVALID_TIMEOUT
from derl.main import main, run
from derl.tracker import get_tracker
_tracker = get_tracker()
_TEST_ARGUMENTS = [
"--retry", str(_TEST_REQUEST_RETRIES),
"--timeout", str(_TEST_REQUESTS_TIMEOUT)
]
class MainTest(TestCase):
maxDiff = None
def _reference_testing(self: "MainTest", arguments: list, reference: str):
with patch("sys.stdout", new=StringIO()) as fake_stdout:
with open(reference, "r") as opened_reference:
with raises(SystemExit) as wrapped_exit:
main(_TEST_ARGUMENTS + arguments)
self.assertEqual(wrapped_exit.type, SystemExit)
self.assertEqual(wrapped_exit.value.code, 0)
self.assertEqual(fake_stdout.getvalue(), opened_reference.read())
def test_main_without_context_without_dispatch(self: "MainTest"):
self._reference_testing([_TEST_DIRECTORY], "tests/references/output-without-context-without-dispatch.out")
def test_main_with_context_without_dispatch(self: "MainTest"):
self._reference_testing([_TEST_DIRECTORY, "--context"],
"tests/references/output-with-context-without-dispatch.out")
def test_main_without_context_with_dispatch(self: "MainTest"):
self._reference_testing([_TEST_DIRECTORY, "--dispatch"],
"tests/references/output-without-context-with-dispatch.out")
def test_main_with_context_with_dispatch(self: "MainTest"):
self._reference_testing([_TEST_DIRECTORY, "--context", "--dispatch"],
"tests/references/output-with-context-with-dispatch.out")
def test_main_with_stats_without_dispatch(self: "MainTest"):
_tracker.set_test()
_tracker.reset()
self._reference_testing([_TEST_DIRECTORY, "--stats"],
"tests/references/output-with-stats-without-dispatch.out")
def test_main_with_stats_with_dispatch(self: "MainTest"):
_tracker.set_test()
_tracker.reset()
self._reference_testing([_TEST_DIRECTORY, "--stats", "--dispatch"],
"tests/references/output-with-stats-with-dispatch.out")
def test_main_with_not_existing_directory(self: "MainTest"):
with raises(SystemExit) as wrapped_exit:
main(["tests/not-existing"])
self.assertEqual(wrapped_exit.type, SystemExit)
self.assertEqual(wrapped_exit.value.code, _INVALID_DIRECTORY)
def test_main_with_invalid_timeout(self: "MainTest"):
with raises(SystemExit) as wrapped_exit:
main(["--dispatch", "--timeout", "-5", _TEST_DIRECTORY])
self.assertEqual(wrapped_exit.type, SystemExit)
self.assertEqual(wrapped_exit.value.code, _INVALID_TIMEOUT)
def test_main_with_invalid_retry(self: "MainTest"):
with raises(SystemExit) as wrapped_exit:
main(["--dispatch", "--retry", "1000", _TEST_DIRECTORY])
self.assertEqual(wrapped_exit.type, SystemExit)
self.assertEqual(wrapped_exit.value.code, _INVALID_RETRY)
def test_run(self: "MainTest"):
with patch("sys.stdout", new=StringIO()) as fake_stdout:
with raises(SystemExit) as wrapped_exit:
run()
self.assertEqual(wrapped_exit.type, SystemExit)
self.assertEqual(wrapped_exit.value.code, 2)
self.assertEqual(fake_stdout.getvalue(), "")
| python |
"""Provides a Discord bot cog containing a collection of simple help commands."""
from typing import Optional
# Third party imports
import discord
from discord.ext import commands
# First party imports
import botpumpkin.discord.message as message_util
from botpumpkin.config import config
# *** Help ******************************************************************
class Help(commands.Cog):
"""Command cog containing a simple collection of help commands."""
def __init__(self, bot: commands.Bot):
"""Initialize the Help cog.
Args:
bot (commands.Bot): The bot the cog will be added to.
"""
self._bot: commands.Bot = bot
# *** help ******************************************************************
@commands.group()
async def help(self, context: commands.Context) -> None:
"""Print information on the current commands supported by the bot.
Args:
context (commands.Context): The context of the command.
"""
if context.invoked_subcommand is None:
description_text: str = "BotPumpkin is a custom bot for starting and stopping our game server, and for doing some other fun and useful things."
embed: discord.Embed = discord.Embed(description = description_text, color = int(config["colors"]["default"], 0))
message_util.add_field_to_embed(embed, "`.slap <user>`", "Let BotPumpkin teach someone else a lesson")
message_util.add_field_to_embed(embed, "`.server start <game>`", "Starts the given game on the game server")
message_util.add_field_to_embed(embed, "`.server stop`", "Stops the game server")
message_util.add_field_to_embed(embed, "`.server change <game>`", "Changes the game running on the game server")
message_util.add_field_to_embed(embed, "`.server status`", "Displays useful status information about the game server")
message_util.add_field_to_embed(embed, "`.help Groovy`", "Displays commonly used commands for Groovy")
message_util.add_field_to_embed(embed, "`.help sesh`", "Displays commonly used commands for sesh")
embed.set_author(name = self._bot.user.name, icon_url = str(self._bot.user.avatar_url))
await context.send(embed = embed)
# *** help groovy ***********************************************************
@help.command(name = "groovy")
async def help_groovy(self, context: commands.Context) -> None:
"""Print a selection of useful commands which are supported by the Groovy Discord bot.
Args:
context (commands.Context): The context of the command.
"""
groovy: Optional[discord.User] = None
for user in self._bot.users:
if user.name == "Groovy":
groovy = user
break
embed_description: str = "Groovy is a bot for playing music in the voice channels. "\
"See [here](https://groovy.bot/commands?prefix=-) for a full list of commands."
embed: discord.Embed = discord.Embed(description = embed_description, color = int(config["colors"]["default"], 0))
message_util.add_field_to_embed(embed, "`-play [query]`", "Adds the song to the queue, and starts playing it if nothing is playing")
message_util.add_field_to_embed(embed, "`-play`", "Starts playing the queue")
message_util.add_field_to_embed(embed, "`-pause`", "Pauses the current song (saves the position in the song)")
message_util.add_field_to_embed(embed, "`-stop`", "Stops the current song (doesn't save the position in the song")
message_util.add_field_to_embed(embed, "`-next`", "Skips to the next song")
message_util.add_field_to_embed(embed, "`-back`", "Skips to the previous song")
message_util.add_field_to_embed(embed, "`-queue`", "Displays the queue contents")
message_util.add_field_to_embed(embed, "`-clear`", "Empties the queue")
message_util.add_field_to_embed(embed, "`-jump [track_position]`", "Jumps to a specific point in the queue")
message_util.add_field_to_embed(embed, "`-shuffle`", "Shuffles the queue")
message_util.add_field_to_embed(embed, "`-move [track_position], [new_position]`", "Moves a song from one position to another in the queue")
message_util.add_field_to_embed(embed, "`-saved queues`", "Displays your saved queues")
message_util.add_field_to_embed(embed, "`-saved queues create [name]`", "Creates the current queue as a new saved queue")
message_util.add_field_to_embed(embed, "`-saved queues load [name]`", "Loads all the songs from a saved queue into the current queue")
message_util.add_field_to_embed(embed, "`-saved queues delete [name]`", "Deletes a saved queue")
if groovy is not None:
embed.set_author(name = groovy.name, icon_url = str(groovy.avatar_url))
else:
embed.set_author(name = "Groovy")
await context.send(embed = embed)
# *** help sesh *************************************************************
@help.command(name = "sesh")
async def help_sesh(self, context: commands.Context) -> None:
"""Print a selection of useful commands which are supported by the sesh Discord bot.
Args:
context (commands.Context): The context of the command.
"""
sesh: Optional[discord.User] = None
for user in self._bot.users:
if user.name == "sesh":
sesh = user
break
embed_description: str = "sesh is a bot for planning hangouts and running polls. "\
"See [here](https://sesh.fyi/manual/) for a full list of commands."
embed: discord.Embed = discord.Embed(description = embed_description, color = int(config["colors"]["default"], 0))
message_util.add_field_to_embed(embed, "`!create [event] [time]`", "Creates a new event with the given event description at the given time")
message_util.add_field_to_embed(embed, "`!poll [name] [options]`", "Creates a new poll with the given name and options")
message_util.add_field_to_embed(embed, "`!list`", "Lists all future scheduled events")
message_util.add_field_to_embed(embed, "`!delete`", "Allows you to select an event to delete")
message_util.add_field_to_embed(embed, "`!delete [query]`", "Searches for an event with a matching name and confirms whether to delete it")
if sesh is not None:
embed.set_author(name = sesh.name, icon_url = str(sesh.avatar_url))
else:
embed.set_author(name = "sesh")
await context.send(embed = embed)
| python |
"""Tests for Ajax API views in the landingzones app"""
from django.urls import reverse
from landingzones.tests.test_views import TestViewsBase
class TestLandingZoneStatusGetAjaxView(TestViewsBase):
"""Tests for the landing zone status getting Ajax view"""
def test_get(self):
"""Test GET request for getting a landing zone status"""
with self.login(self.user):
response = self.client.get(
reverse(
'landingzones:ajax_status',
kwargs={'landingzone': self.landing_zone.sodar_uuid},
)
)
self.assertEqual(response.status_code, 200)
expected = {
'status': self.landing_zone.status,
'status_info': self.landing_zone.status_info,
}
self.assertEquals(response.data, expected)
| python |
# -*- coding: utf-8 -*-
from django.contrib import admin
from .models import Project, Category, Post, Contact
@admin.register(Project)
class ProjectAdmin(admin.ModelAdmin):
list_display = (
'id',
'title',
'slug',
'image',
'live_site',
'github_link',
'description',
)
search_fields = ('slug',)
@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'slug')
search_fields = ('slug',)
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = (
'id',
'title',
'slug',
'overview',
'body',
'image',
'created_on',
'updated_on',
'status',
)
list_filter = ('created_on', 'updated_on')
raw_id_fields = ('categories',)
search_fields = ('slug',)
@admin.register(Contact)
class ContactAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'email', 'message')
search_fields = ('name',)
| python |
from mysql.connector import Error
import mysql.connector
from utils import configs
from database.connection import conn
from loguru import logger
def create_employee(employee):
c = conn.cursor()
try:
query = ("INSERT INTO employees(name, user_id, check_in, check_out,"
" work_date, prediction_checkin, prediction_checkout,"
" created_at, updated_at, check_in_image, check_out_image)"
" VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
task = (employee.name, employee.user_id, employee.check_in,
employee.check_out, employee.work_date,
employee.prediction_checkin, employee.prediction_checkout,
employee.created_at, employee.updated_at,
employee.check_in_image, employee.check_out_image)
c.execute(query, task)
conn.commit()
logger.info("Record inserted successfully into Employees table.")
except Error as e:
logger.error(e)
return
def check_employee(employee):
c = conn.cursor()
query_check = "SELECT *FROM employees WHERE user_id=%s AND work_date=%s"
input = (employee.user_id, employee.work_date)
c.execute(query_check, input)
result = c.fetchone()
if result:
logger.info("Employee's information is existing on DB.")
return True
return False
def update_database(employee):
conn_ = mysql.connector.connect(
host="localhost", database="db", user="root"
)
c = conn_.cursor()
try:
query = '''UPDATE employees SET updated_at = %s, check_out = %s,
check_out_image = %s, prediction_checkout = %s
WHERE user_id = %s AND work_date = %s'''
input = (employee.updated_at, employee.updated_at,
employee.check_out_image, employee.prediction_checkout,
employee.user_id, employee.work_date)
c.execute(query, input)
conn_.commit()
logger.info("Successfully in updated information of check out.")
except Error as e:
logger.error(e)
return
| python |
import click
from itertools import tee
from . import fasta
def load(msafp, reference, seqtype):
sequences = fasta.load(msafp, seqtype)
ref_finder, sequences = tee(sequences, 2)
if reference:
try:
refseq = next(
ref
for ref in ref_finder
if ref.header == reference
)
except StopIteration:
raise click.ClickException(
'Unable to locate reference {!r} (--reference)'
.format(reference)
)
else:
refseq = next(ref_finder)
for seq in sequences:
if seq != refseq:
yield refseq, seq
| python |
import heterocl as hcl
import os, sys
import numpy as np
def test_stages():
A = hcl.placeholder((32, 32), "A")
# C = hcl.placeholder((32, 32), "C")
def kernel(A):
B = hcl.compute(A.shape, lambda i, j : A[i, j] + 1, "B")
C = hcl.compute(A.shape, lambda i, j : A[i, j] + 1, "C")
D = hcl.compute(A.shape, lambda i, j : B[i, j] + 1, "D")
E = hcl.compute(A.shape, lambda i, j : C[i, j] + 1, "E")
F = hcl.compute(A.shape, lambda i, j : D[i, j] + E[i, j], "F")
return F
target = hcl.Platform.xilinx_zc706
target.config(compiler="vivado_hls", mode="csim", project="stages-depth-1-new.prj")
s = hcl.create_schedule([A], kernel)
s.to(A, target.xcel)
s.to(kernel.B, s[kernel.D], fifo_depth=1)
s.to(kernel.C, s[kernel.E], fifo_depth=1)
s.to(kernel.D, s[kernel.F], fifo_depth=1)
s.to(kernel.E, s[kernel.F], fifo_depth=1)
s.to(kernel.F, target.host)
mod = hcl.build(s, target=target)
print(mod.src)
mod()
# np_A = np.zeros((32, 32))
# np_C = np.zeros((32, 32))
# np_F = np.zeros((32, 32))
# hcl_A = hcl.asarray(np_A)
# hcl_C = hcl.asarray(np_C)
# hcl_F = hcl.asarray(np_F)
# mod(hcl_A, hcl_C)
# report = mod.report()
# report.display()
if __name__ == "__main__":
test_stages() | python |
import jax
import jax.numpy as jnp
def standardize_signs(v: jnp.ndarray) -> jnp.ndarray:
"""Get `w = s*v` such that `max(abs(w)) == max(w) >= 0` and `abs(s) == 1`."""
val = v[jnp.argmax(jnp.abs(v))]
if v.dtype in (jnp.complex64, jnp.complex128):
return v * jnp.abs(val) / val # make real
return v * jnp.sign(val)
def standardize_eigenvector_signs(v: jnp.ndarray) -> jnp.ndarray:
"""Get eigenvectors with standardized signs. See `standardize_signs`."""
return jax.vmap(standardize_signs, 1, 1)(v)
def symmetrize(A: jnp.ndarray) -> jnp.ndarray:
"""Make symmetric and hermitian."""
return (A + A.conj().T) / 2
| python |
# -*- coding: utf-8 -*-
# (C) 2013-2018,2020 Muthiah Annamalai
#
# This file is part of 'open-tamil' package tests
#
# setup the paths
import unittest
from opentamiltests import *
from tamil.utf8 import get_letters
from transliterate import azhagi, jaffna, combinational, UOM, ISO, itrans, algorithm
class ReverseTransliterationTests(unittest.TestCase):
def test_tamil2en_1(self):
tamil_str = u"வணக்கம்"
azhagi_table = azhagi.Transliteration.table
eng_str = algorithm.Tamil2English.transliterate(azhagi_table, tamil_str)
self.assertEqual(eng_str, u"vaNacKam")
tamil_str = u"அன்னம்"
azhagi_table = azhagi.Transliteration.table
eng_str = algorithm.Tamil2English.transliterate(azhagi_table, tamil_str)
self.assertEqual(eng_str, u"annHam")
tamil_str = u"இறையோன்"
exp_eng_str = "iRaiyOn"
eng_str = algorithm.Tamil2English.transliterate(azhagi_table, tamil_str)
self.assertEqual(eng_str, exp_eng_str)
class ISOTest(unittest.TestCase):
def test_tables(self):
self.assertEqual(len(ISO.ReverseTransliteration.table), len(ISO.Transliteration.table))
def test_ISO(self):
ISO_table = ISO.ReverseTransliteration.table
expected = 'cāmi. citamparaṉār nūṟ kaḷañciyam'
tamil_str = "சாமி. சிதம்பரனார் நூற் களஞ்சியம்"
eng_str = algorithm.Direct.transliterate(ISO_table, tamil_str)
self.assertEqual(expected, eng_str)
def test_issue_237(self):
ISO_table = ISO.ReverseTransliteration.table
expected = 'pāvēntam'
tamil_str = "பாவேந்தம்"
eng_str = algorithm.Direct.transliterate(ISO_table, tamil_str)
self.assertEqual(expected, eng_str)
def test_issue_239(self):
ISO_table = ISO.ReverseTransliteration.table
expected = 'tiyākarājaṉ'
tamil_str = "தியாகராஜன்"
eng_str = algorithm.Direct.transliterate(ISO_table, tamil_str)
self.assertEqual(expected, eng_str)
class GreedyTests(unittest.TestCase):
@unittest.skip("incorrect")
def test_ISO(self):
ISO_table = algorithm.reverse_transliteration_table(ISO.Transliteration.table)
expected = 'cāmi. citamparaṉār nūṟ kaḷañciyam'
tamil_str = "சாமி. சிதம்பரனார் நூற் களஞ்சியம்"
eng_words = []
for tamil_word in tamil_str.split(' '):
_, eng_str = algorithm.Greedy.transliterate(ISO_table, tamil_word, full_search=True)
print(eng_str.options)
if len(eng_str.options) < 1: continue
eng_str.options = list(eng_str.options)
eng_words.append(eng_str.options[0])
eng_fullstr = ' '.join(eng_words)
self.assertEqual(expected, eng_fullstr)
def test_UOM(self):
# University of Madras Lexicon style transliteration standard
tamil_word = u"வணக்கம்"
for eng_string in [u"vṇikkim"]:
top_match, greedy = algorithm.Greedy.transliterate(
UOM.Transliteration.table, eng_string
)
# import pprint
# pprint.pprint(greedy.options)
self.assertTrue(tamil_word in greedy.options)
def test_vanakkam(self):
tamil_word = u"வணக்கம்"
for eng_string in ["vaNakkam", "vanakkam"]:
top_match, greedy = algorithm.Greedy.transliterate(
jaffna.Transliteration.table, eng_string
)
self.assertTrue(tamil_word in greedy.options)
class Yazhpanam(unittest.TestCase):
def test_vandemataram(self):
tamil_words = u"வந்தே மாதரம்"
eng_string = u"vanthE mAtharam"
tamil_tx = algorithm.Iterative.transliterate(
jaffna.Transliteration.table, eng_string
)
if LINUX:
print(
"]" + tamil_tx + "[",
len(tamil_words),
len(tamil_tx),
type(tamil_tx),
type(tamil_words),
)
if LINUX:
print("]" + tamil_words + "[")
self.assertTrue(tamil_words == tamil_tx)
def test_combinational(self):
tamil_words = u"வந்தே மாதரம்"
eng_string = u"van-thee maatharam"
tamil_tx = algorithm.Iterative.transliterate(
combinational.Transliteration.table, eng_string
)
if LINUX:
print(
"]" + tamil_tx + "[",
len(tamil_words),
len(tamil_tx),
type(tamil_tx),
type(tamil_words),
)
if LINUX:
print("]" + tamil_words + "[", len(tamil_tx), len(tamil_words))
self.assertTrue(tamil_words.find(tamil_tx) >= 0)
def test_azhagi_spec(self):
# test for
tamil_tx = {}
correct_tx = {
u"ke": u"கெ",
u"khae": u"கே",
u"cai": u"கை",
u"koh": u"கொ",
u"kho": u"கோ",
}
for eng_string in [u"ke", u"khae", u"cai", u"koh", u"kho"]:
tamil_tx[eng_string] = algorithm.Iterative.transliterate(
azhagi.Transliteration.table, eng_string
)
if LINUX:
print(tamil_tx[eng_string], " => ", eng_string)
self.assertTrue(tamil_tx[eng_string], eng_string)
def test_azhagi(self):
## challenge use a probabilistic model on Tamil language to score the next letter,
## instead of using the longest/earliest match
## http://www.mazhalaigal.com/tamil/learn/keys.php
codes = {
"neenga": u"நீங்க",
"andam": u"அண்டம்",
"nandri": u"நன்றி",
"katru": u"கற்று",
"viswam": u"விஸ்வம்",
"namaskaaram": u"நமஸ்காரம்",
"sreedhar": u"ஸ்ரீதர்",
"manju": u"மஞ்சு",
"gnaayam": u"ஞாயம்",
"poi": u"பொய்",
"kaai": u"காய்",
"aGnGnaanam": u"அஞ்ஞானம்",
"mei": u"மெய்",
"nanghu": u"நன்கு",
"palancaL": u"பலன்கள்",
"payanKaL": "பயன்கள்",
"avanThaan": u"அவன்தான்",
"leoni": u"லியோனி",
"paeTrik": u"பேட்ரிக்",
"peTroal": u"பெட்ரோல்",
"coapanHaegan": u"கோபன்ஹேகன்",
"bandham": u"பந்தம்",
"saantham": u"சாந்தம்",
"kaeLvi": u"கேள்வி",
"koavil": u"கோவில்",
"nhagar": u"நகர்",
"maanhagaram": u"மாநகரம்",
"senhnheer": u"செந்நீர்",
}
tamil_words = u""
for eng_string, tamil_words in codes.items():
tamil_tx = algorithm.Iterative.transliterate(
azhagi.Transliteration.table, eng_string
)
if LINUX:
print(
"]" + tamil_tx + "[",
len(tamil_words),
len(tamil_tx),
"]" + tamil_words + "[",
)
# self.assertTrue( tamil_words == tamil_tx ) #we are almost there but not yet
def test_devotional(self):
for k, v in {
u"thiruvaachakam": u"திருவாசகம்",
u"mANikka vAsagar": u"மாணிக்க வாசகர்",
}.items():
tamil_tx = algorithm.Iterative.transliterate(
azhagi.Transliteration.table, k
)
if tamil_tx != v:
raise Exception(
u"Transliteration changed\n Expected %s, but got %s for string input %\n"
% (v, tamil_tx, k)
)
return
class DubashTest(unittest.TestCase):
def test_multi_lang(self):
test_str = u"அம்மா ammA"
expected_str = u"அம்மா அம்மா"
tamil_tx = algorithm.BlindIterative.transliterate(
azhagi.Transliteration.table, test_str
)
self.assertEqual(tamil_tx, expected_str)
return
def test_multi_lang2(self):
test_str = u"அம்மா ammA"
expected_str = u"அம்மா அம்மா"
tamil_tx = algorithm.Iterative.transliterate(
azhagi.Transliteration.table, test_str
)
self.assertEqual(tamil_tx, expected_str)
return
class ITRANSTest(unittest.TestCase):
def test_vanakkam_itrans(self):
tamil_word = "வணக்கம்"
for eng_string in ["vaNakkam"]:
tamil_tx = algorithm.Iterative.transliterate(
itrans.Transliteration.table, eng_string
)
self.assertEqual(tamil_word, tamil_tx)
if __name__ == "__main__":
unittest.main()
| python |
from userinput import userinput
import pytest
def test_hostname(monkeypatch):
monkeypatch.setattr('builtins.input', lambda x: "localhost")
assert userinput("user_input", validator="hostname", cache=False)
monkeypatch.setattr('builtins.input', lambda x: "guguwgjwgdwkdjgwkjdgj")
with pytest.raises(ValueError):
userinput("user_input", validator="hostname", cache=False, maximum_attempts=3) | python |
from django.db import models
from .managers import StatusManager
class OsnovniPodatki(models.Model):
oznaka = models.CharField(max_length=100, blank=True, null=True)
oznaka_gen = models.CharField(max_length=100, blank=True, null=True)
naziv = models.CharField(max_length=255, blank=True, null=True)
opis = models.TextField(blank=True, null=True)
class Meta:
abstract = True
class TimeStampedModel(models.Model):
created = models.DateTimeField(auto_now_add=True, blank=True, null=True)
updated = models.DateTimeField(auto_now=True, blank=True, null=True)
class Meta:
abstract = True
class IsActiveModel(models.Model):
is_active = models.BooleanField(default=True)
class Meta:
abstract = True
class IsLikvidiranModel(models.Model):
is_likvidiran = models.BooleanField(default=False)
class Meta:
abstract = True
class ZaporednaStevilka(models.Model):
zap_st = models.IntegerField(default=9999, verbose_name="zaporedna številka")
class Meta:
abstract = True
class ObdobjeLeto(models.Model):
oznaka = models.IntegerField(primary_key=True)
# META AND STRING
# ------------------------------------------------------
class Meta:
ordering = ('-oznaka',)
def __str__(self):
return "%s" % (self.oznaka)
class ObdobjeMesec(models.Model):
oznaka = models.IntegerField(primary_key=True)
naziv = models.CharField(max_length=10)
def __str__(self):
return "%s" % (self.naziv)
class StatusModel(models.Model):
draft = 0
vCakanju = 1
vPlanu = 2
vResevanju = 3
zakljuceno = 4
deleted = 5
neaktivno = 6
STATUS = (
(draft, 'draft'),
(vCakanju, 'v čakanju'),
(vPlanu, 'v planu'),
(vResevanju, 'v reševanju'),
(zakljuceno, 'zaključeno'),
(deleted, 'izbrisano'),
(neaktivno, 'neaktivno'),
)
status = models.IntegerField(default=0, choices=STATUS)
# MODEL Manager
objects = StatusManager()
class Meta:
abstract = True
class PrioritetaModel(models.Model):
nizka = 0
normalna = 1
velika = 2
PRIORITETA = (
(nizka, 'Nizka prioriteta'),
(normalna, 'Normalna'),
(velika, 'Velika prioriteta - Nujno'),
)
prioriteta = models.IntegerField(default=1, choices=PRIORITETA)
class Meta:
abstract = True
class Opombe(models.Model):
opombe = models.TextField(null=True, blank=True)
class Meta:
abstract = True
# Kombinacije
class OsnovnaKombinacija(OsnovniPodatki, TimeStampedModel, StatusModel):
class Meta:
abstract = True
| python |
import pandas as pd
import glob
data_path = 'E:/GenderClassification/PycharmProjects/GenderClassification/home/abeer/Dropbox/Dataset_HAR project/*'
addrs = glob.glob(data_path)
for i in addrs:
folders = glob.glob(i + '/Walk/Esphalt/Alone/*')
for j in folders:
csv_files = glob.glob(j + '/*')
LUA = pd.read_csv('initAcc.csv')
RC = pd.read_csv('initAcc.csv')
LC = pd.read_csv('initAcc.csv')
back = pd.read_csv('initAcc.csv')
waist = pd.read_csv('initAcc.csv')
RUA = pd.read_csv('initAcc.csv')
LeftWatch = pd.read_csv('initAcc.csv')
RightWatch = pd.read_csv('initAcc.csv')
for k in csv_files:
if '(1)' in k or '(2)' in k or '(3)' in k or '(4)' in k or '(5)' in k:
continue
elif 'Accelerometer' in k and 'F5-RC' in k:
file = pd.read_csv(k)
RC = RC.append(file.iloc[:, 3:])
RC = RC.reset_index(drop=True)
print(RC.columns)
elif 'Accelerometer' in k and "DE-Waist" in k:
file = pd.read_csv(k)
waist = waist.append(file.iloc[:, 3:])
waist = waist.reset_index(drop=True)
elif 'Accelerometer' in k and "D5-LC" in k:
file = pd.read_csv(k)
LC = LC.append(file.iloc[:, 3:])
LC = LC.reset_index(drop=True)
elif 'Accelerometer' in k and "D2-RUA" in k:
file = pd.read_csv(k)
RUA = RUA.append(file.iloc[:, 3:])
RUA = RUA.reset_index(drop=True)
elif 'Accelerometer' in k and "C6-back" in k:
file = pd.read_csv(k)
back = back.append(file.iloc[:, 3:])
back = back.reset_index(drop=True)
elif 'Accelerometer' in k and "C5-LUA" in k:
file = pd.read_csv(k)
LUA = LUA.append(file.iloc[:, 3:])
LUA = LUA.reset_index(drop=True)
for k in csv_files:
if '(1)' in k or '(2)' in k or '(3)' in k or '(4)' in k or '(5)' in k:
continue
elif 'Gyroscope' in k and 'F5-RC' in k:
file = pd.read_csv(k)
file = file.iloc[:, 3:]
RC = pd.concat([RC, file], axis=1)
print(RC.columns)
print(RC.info())
elif 'Gyroscope' in k and "DE-Waist" in k:
file = pd.read_csv(k)
file = file.iloc[:, 3:]
waist = pd.concat([waist, file], axis=1)
elif 'Gyroscope' in k and "D5-LC" in k:
file = pd.read_csv(k)
file = file.iloc[:, 3:]
LC = pd.concat([LC, file], axis=1)
elif 'Gyroscope' in k and "D2-RUA" in k:
file = pd.read_csv(k)
file = file.iloc[:, 3:]
RUA = pd.concat([RUA, file], axis=1)
elif 'Gyroscope' in k and "C6-back" in k:
file = pd.read_csv(k)
file = file.iloc[:, 3:]
back = pd.concat([back, file], axis=1)
elif 'Gyroscope' in k and "C5-LUA" in k:
file = pd.read_csv(k)
file = file.iloc[:, 3:]
LUA = pd.concat([LUA, file], axis=1)
ef = LUA.to_csv(j +'/C5-LUA.csv', index=None)
ef = RUA.to_csv(j +'/D2-RUA.csv', index=None)
ef = waist.to_csv(j +'/DE-Waist.csv', index=None)
ef = back.to_csv(j +'/C6-back.csv', index=None)
ef = LC.to_csv(j +'/D5-LC.csv', index=None)
ef = RC.to_csv(j +'/F5-RC.csv', index=None)
| python |
#! usr/bin/env python3
# -*- coding: utf-8 -*-
'''
#-------------------------------------------------------------------------------
Project : Project JaaS
Module : membership_manager
Purpose : Add new users & check membership status of existing ones
Version : 0.1.1 beta
Status : Development
Modified : 2020 Mar 04
Created : 2020 Mar 04
Author : Burak Tokman
Email : [email protected]
Copyright : 2020, Bulrosa OU
Licence : EULA
Unauthorized copying of this file, via any medium is strictly prohibited
Proprietary and confidential
#-------------------------------------------------------------------------------
'''
from pathlib import Path
from psaw import PushshiftAPI
from datetime import datetime as dt
from colorama import Fore, Back, Style
import os
import sys
import time
import json
import requests
import random
import praw
sys.path.insert(0, str(Path(Path(__file__).parents[0] / 'lib')))
import logz
import postgres
CONFIG = {'refresh-interval': 10 # mins
}
def check_membership_status(user):
"""
"""
time_now_unix = int(time.time())
time_membership_end_unix = int(time.mktime(dt.strptime(user['membership_time_end'], "%Y-%m-%d %H:%M:%S").timetuple()))
if time_membership_end_unix > time_now_unix:
return True
else:
return False
def main():
# Connect to DB
postgres.connect_db()
while True:
# Start
time_start = time.time()
# ------ FETCH USERS ---------------------------
print(f"{logz.timestamp()}{Fore.GREEN} MEMBERSHIP → INIT → {Style.RESET_ALL}Fething users...")
# From database
users_database = postgres.get_user_all()
# From Shopify (or ?)
# ----------------------------------------------
# # # # # # # # # # #
# #
# MANAGE #
# #
# # # # # # # # # # #
# ------ OLD USERS -----------------------------
print(f"{logz.timestamp()}{Fore.GREEN} MEMBERSHIP → EXISTING → {Style.RESET_ALL}Checking expired memberships")
for user in users_database:
# Check if membership of existing users
if check_membership_status(user) == False:
print(f"{logz.timestamp()}{Fore.GREEN} MEMBERSHIP → CAUTION → {Style.RESET_ALL}User {user['id']} membership expired")
r = postgres.set_user_membership_status(user_id=user['id'],
status=False)
# ------ NEW USERS -----------------------------
#
# INCOMPLETE - FETCH FROM WHERE?
#
# users_remote = shopify.get_orders()
# for user in users_remote:
# for user_local in users_database:
# if user_local['email'] == user['email']:
# # Add user to database
# # Send Welcome joke
# # Mark joke as sent
# break
# ------ SLEEP ---------------------------------
print(f"{logz.timestamp()}{Fore.GREEN} MEMBERSHIP → COMPLETED → {Style.RESET_ALL}Sleeping {CONFIG['refresh-interval'] * 60}mins")
time.sleep(CONFIG['refresh-interval'] * 60)
if __name__ == '__main__':
main()
| python |
import inspect
from copy import deepcopy
import re
class ConfigManage:
"""
Provides methods for managing parameter configuration for all DataWorker/DataInterface classes
(must inherit this class).
Each parameter:
specifies some documentation (or retrieves with super().doc(param_name)) for the help button on GUI,
specifies the input type for the GUI layout (see ConfigGenInputDef),
specifies the check string (see configobj package documentation for validator) for the check button on GUI
Each DataWorker/DataInterface class can add additional parameters (required or optional) in the format
{'required': {'req_param_1': {'doc': 'documentation',
'input': 'input_definition function',
'validate': 'check string for validator'
},
'req_param_2': {...}
},
'optional': {opt_param_1': {...}
}
}
Then, a call to super().update_config(self.cfg, additional_cfg) will update the class configuration.
To utilize, specify a @classmethod with name set_config in the DataWorker/DataInterface class and include
the additional_config and a call to update_config. Then, after the class definition put class.set_config()
to call the class method which will setup the class configuration.
Note: when building a DataWorker/DataInterface by inheriting from another, if you only need to change one
parameter specification like the documentation you don't need the 'input' or 'validate' keys in the
additional_config dictionary for that parameter.
Note: a parameter should not be both required and optional (do not use same name for required and optional)
"""
# Default Configuration Setup for all DataWorkers/DataInterfaces
cfg = {'required': {},
'optional': {}}
@classmethod
def get_doc(cls, parameter: str) -> str:
"""
Get the documentation from interface iget* function for parameter
:param parameter: parameter name for documentation lookup
:return:
"""
special_function_name, = [func for func in dir(cls) if func.startswith('iget')]
special_function = getattr(cls, special_function_name)
docstring = ''.join([docstring for docstring in re.split(':param |:return:', inspect.getdoc(special_function))
if docstring.startswith(parameter + ':')])
return docstring
@staticmethod
def update_config(base_cfg: dict, additional_cfg: dict) -> dict:
"""
Update configuration dictionary with additional configurations
:param base_cfg: the configuration dictionary to be updated
:param additional_cfg: the additional configurations dictionary
:return:
"""
# Dictionary format cfg[required/optional][parameter][documentation/input/check]
return_cfg = deepcopy(base_cfg)
for req_opt_key in list(return_cfg.keys()):
if req_opt_key not in additional_cfg.keys():
# Additional Configuration does not have a (required/optional) parameter
continue
for param_key in list(additional_cfg[req_opt_key].keys()):
if param_key in return_cfg[req_opt_key].keys():
return_cfg[req_opt_key][param_key].update(additional_cfg[req_opt_key][param_key])
else:
return_cfg[req_opt_key][param_key] = additional_cfg[req_opt_key][param_key]
return return_cfg
| python |
#!/usr/bin/env python
# __BEGIN_LICENSE__
# Copyright (C) 2006-2011 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# __END_LICENSE__
from __future__ import with_statement
import sys
import os
from subprocess import Popen, PIPE
class Graph(object):
def __init__(self, seq):
self.e = set()
self.v1 = set()
self.v2 = {}
for line in seq:
line = line.strip()
if not line:
continue
left, right = line.split()
self.e.add((left, right))
self.v1.add(left)
self.v1.add(right)
def assign_depth(self):
print >>sys.stderr, 'there are %i nodes' % len(self.v1)
for v in self.leaves():
self.v1.discard(v)
self.v2[v] = 0
last = 10000000000000000
times = 0
while self.v1:
cur = len(self.v1)
print >>sys.stderr, 'now there are %i nodes' % cur
if cur == last:
times += 1
if times > 10:
raise Exception('ERROR: Cycle! Nodes: %s' % self.v1)
else:
last = cur
times = 0
kill = set()
for v in self.v1:
children = self.children_of(v)
if set(children).issubset(self.v2.keys()):
self.v2[v] = max([self.v2[i] for i in children])+1
kill.add(v)
self.v1.difference_update(kill)
print >>sys.stderr, 'now there are 0 nodes'
def leaves(self):
r = set([i[1] for i in self.e])
r.difference_update([i[0] for i in self.e])
return r
def children_of(self, v):
return [i[1] for i in self.e if i[0] == v]
if __name__ == '__main__':
args = len(sys.argv)
infile = None
outfile = None
if args == 3:
outfile = sys.argv[1]
infile = sys.argv[2]
elif args == 2:
outfile = sys.argv[1]
else:
print >>sys.stderr, 'Usage: %s output-file' % sys.argv[0]
sys.exit(-1)
with file(outfile, 'w') as f:
if infile is None:
grep = Popen(['grep', '-rI', '#include.*<vw', os.path.abspath(os.path.dirname(sys.argv[0]) + '/../src/vw')], stdout=PIPE)
sed = Popen(['sed', '-e', 's#^.*src/\(vw[^:]\+\):.*<\([^>]\+\)>#\\1 \\2#'], stdin=grep.stdout, stdout=PIPE)
filt = Popen(['grep', '-v', '\(.cc\|/tests\|/GPU\)'], stdin=sed.stdout, stdout=PIPE)
outf = filt.communicate()[0]
else:
outf = file(infile, 'r').read()
g = Graph(outf.split('\n'))
g.assign_depth()
print >>f, '\n'.join(map(lambda x: '%i\t%s' % (x[1], x[0]), sorted(g.v2.items(), key=lambda x: (x[1],x[0]))))
| python |